uva ID codes

用next_permutation 秒

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <fstream>
#include <math.h>
#include <algorithm>
using namespace std;
int cmp(const void *p1,const void *p2){
    char *a = (char *)p1;char *b = (char *)p2;
    return (*a)>(*b)?1:-1;
}
int main()
{
    //ifstream cin("ha.txt");
    char s[55],temp[55];
    int n;
    while(cin>>s)
    {
        if(s[0]=='#'){return 0;}
        n = strlen(s);
        strcpy(temp,s);
        qsort(temp,n,sizeof(char),cmp);
        next_permutation(s,s+n);
        if(strcmp(s,temp)==0){
            cout<<"No Successor"<<endl;
        }
        else{
            cout<<s<<endl;
        }
    }
}


你可能感兴趣的:(uva ID codes)