参考:https://blog.csdn.net/hoaresky1998/article/details/51351588
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <set> 5 #include <map> 6 #include <algorithm> 7 using namespace std; 8 map<string,int> ma; 9 set<string> sea; 10 string change(string x) 11 { 12 for (unsigned int i=0;i<x.length();i++) 13 { 14 x[i]=towlower(x[i]); 15 } 16 sort(x.begin(),x.end());//排序string类型的方法 17 return x; 18 } 19 int main() 20 { 21 // freopen("in.txt","r",stdin); 22 string s; 23 while (cin>>s) 24 { 25 if (s=="#") 26 { 27 break; 28 } 29 sea.insert(s);//运用set自身的有序性 30 string temp=change(s);//转化为小写形式,且字母按字典序排序 31 if (!ma.count(temp)) 32 { 33 ma[temp]=1; 34 } 35 else 36 { 37 ma[temp]++; 38 } 39 } 40 set<string>::iterator it; 41 for (it=sea.begin();it!=sea.end();it++) 42 { 43 if (ma[change(*it)]==1) 44 { 45 cout<<*it<<endl; 46 } 47 } 48 49 return 0; 50 }
原文地址:https://www.cnblogs.com/hemeiwolong/p/9600837.html
时间: 2024-10-06 01:20:03