Uva 156.Ananagrams
写麻烦了貌似
不过算同时复习了下 vector set map
1 #include <cstdio> 2 #include <set> 3 #include <map> 4 #include <string> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 #include <vector> 9 using namespace std; 10 11 int read(char s[]){ 12 char c; 13 int i=0; 14 while(!(((c=getchar())>='A'&&c<='Z')||(c>='a'&&c<='z'))) 15 if(c=='#') 16 return 0; 17 while((c>='A'&&c<='Z')||(c>='a'&&c<='z')){ 18 s[i++]=c; 19 c=getchar(); 20 } 21 s[i]='\0'; 22 return i; 23 } 24 25 string code(char s[]){ 26 int i=0; 27 char s2[100]; 28 while(s[i]!='\0'){ 29 s2[i]=(s[i]>='A'&&s[i]<='Z'?s[i]-'A'+'a':s[i]); 30 i++; 31 } 32 s2[i]='\0'; 33 sort(s2,s2+strlen(s2)); 34 return s2; 35 } 36 37 int main(){ 38 //freopen("in.txt","r",stdin); 39 set<string> s; 40 set<string>::iterator it; 41 map<string,string> m; 42 map<string,string>::iterator it_map; 43 44 char str[100]; 45 while(read(str)){ 46 string temp=code(str); 47 //cout<<str<<" "<<temp<<endl; 48 it_map=m.find(temp); 49 if(it_map==m.end()){ 50 m.insert(pair<string,string>(temp,str)); 51 s.insert(temp); 52 } 53 else 54 s.erase(temp); 55 } 56 57 vector<string> v; 58 for(it=s.begin();it!=s.end();it++) 59 v.push_back(m.find(*it)->second); 60 sort(v.begin(),v.end()); 61 62 for(size_t i=0;i<v.size();i++) 63 cout<<v[i]<<endl; 64 65 return 0; 66 }
然而,我并不能保证我说的是对的。请自行验证,如有错误,请指正
新博客地址
https://www.oyohyee.com
https://www.oyohyee.com