閱讀388 返回首頁    go 阿裏雲 go 技術社區[雲棲]


POJ1146

這題就是求字典序的下一個排列 用STL裏的next_permutation函數就能輕鬆解決 

處理過這種問題 在加上sort函數 很巧妙的解決了問題

#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
    char yl[55],as[55];
    while(~scanf("%s",yl)&&strcmp(yl,"#")!=0)
    {
        int len=strlen(yl),n=0;
        strcpy(as,yl);
        sort(as,as+len);
        next_permutation(yl,yl+len);
        if(strcmp(yl,as)==0)
            cout<<"No Successor"<<endl;
        else
            cout<<yl<<endl;
    }
    return 0;
}


最後更新:2017-04-04 07:03:32

  上一篇:go BookService數組調用
  下一篇:go ActivityGroup中出現的Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@