cf-B-Azamon Web Services

Link
(today sleep until 11 o'clock up, my mind is not clear it. Hey ... so simple a question)
priority to find the front of the character substitutions to replace the smallest character behind (when there are multiple, with priority behind)

#include<bits/stdc++.h>
using namespace std;
char s1[5010],s2[5010];
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%s",s1);scanf("%s",s2);int ml=strlen(s1);
        if(strcmp(s1,s2)<0) cout<<s1<<endl;
        else {
            int len=0;
            int id=0,f=0;
            for(int i=0;i<ml;++i){
                char Min=s1[i];
                len=ml-1;id=i;
                while(len>i){
                    if(s1[len]<Min) Min=s1[len],id=len;
                    --len;
                }
                f=i;
                if(id==i) continue;
                else break;
            }
            swap(s1[f],s1[id]);
            if(strcmp(s1,s2)<0) cout<<s1<<endl;
            else cout<<"---"<<endl;
        }
    }
    return 0;
}


Published 96 original articles · won praise 11 · views 2274

Guess you like

Origin blog.csdn.net/weixin_43769146/article/details/103550773