题目链接: http://poj.org/problem?id=1256
题意: 根据自定义的字典序: ‘A‘<‘a‘<‘B‘<‘b‘<...<‘Z‘<‘z‘ 和输入的字符串(最长为13), 输出按新字典序的全排列.
分析: 题目简单, 但是要处理好映射关系.
1 #include <iostream> 2 #include <string> 3 #include <algorithm> 4 using namespace std; 5 6 int mp[13]; // 字符串中的各个字符按相对大小映射到mp中. 7 8 int main(){ 9 int T,n; 10 cin>>T; 11 while(T--){ 12 string s; 13 cin>>s; 14 int len = s.length(); 15 for(int i=0;i<len;++i){ 16 if(s[i]>=‘a‘ && s[i] <= ‘z‘){ 17 mp[i] = (s[i]-‘a‘)*2+1; 18 }else{ 19 mp[i] = (s[i]-‘A‘)*2; 20 } 21 } 22 sort(mp,mp+len); 23 do{ 24 for(int i=0;i<len;++i){ 25 char c; 26 if(mp[i]%2){ 27 c = ‘a‘+mp[i]/2; 28 }else{ 29 c = ‘A‘+mp[i]/2; 30 } 31 cout<<c; 32 } 33 cout<<endl; 34 }while(next_permutation(mp,mp+len)); 35 } 36 return 0; 37 }
原文:http://www.cnblogs.com/roger9567/p/4887316.html