UVa 195 Anagram

解題:使用STL next_permutaion & 自建比較排序
Code:
 1  #include<cstdio>
 2  #include<cstdlib>
 3  #include<iostream>
 4  #include<algorithm>
 5  #include<cctype>
 6  #include<cstring>
 7  using namespace std;
 8  bool cmp(char a,char b)
 9  {
10      char la=a,lb=b;
11      la=tolower(la),lb=tolower(b);
12      if(la==lb)
13      {
14          return a<b;
15      }
16      else return la<lb;
17  }
18  int main()
19  {
20      int cas;
21      while(cin>>cas)
22      {
23          for(int i=0; i<cas; i++)
24          {
25              string str;
26              cin>>str;
27              sort(str.begin(),str.end(),cmp);
28              do
29              {
30                  printf("%s\n", str.c_str());
31              }
32              while( next_permutation(str.begin(), str.end(), cmp) );
33          }
34      }
35      return 0;

36  }

留言

這個網誌中的熱門文章

Things a Little Bird Told Me: Confessions of the Creative Mind

UVa 12970 Alcoholic Pilots

UVa 483 Word Scramble