A Uva10815
#include<set> #include<string> #include<sstream>//stringstream #include<iostream> using namespace std; set<string> se; int main() { string x,y; while(cin>>x){ for (int i = 0; i < x.length(); ++i) if(isalpha(x[i])) x[i]=tolower(x[i]);//isalpha(x[i]) 判断是否为字母,tolower(x[i) 改编为小写字母 else x[i]=' '; stringstream ss(x);//文件流 while(ss>>y) se.insert(y); } for (set<string>::iterator j = se.begin(); j !=se.end() ; ++j) { cout<<*j<<' '; } return 0; }
C HDU -1412
1 #include<iostream> 2 #include<set> 3 using namespace std; 4 set<int >se; 5 int main() 6 { 7 8 int n,m; 9 while(scanf("%d%d",&n,&m)!=EOF) 10 { 11 int x; 12 for(int i=0;i<n;i++){ 13 scanf("%d",&x); 14 se.insert(x); 15 } 16 for(int i=0;i<m;i++){ 17 scanf("%d",&x); 18 se.insert(x); 19 } 20 set<int>::iterator it; 21 int flag=1; 22 for(it=se.begin();it!=se.end();it++) 23 { 24 if(flag) 25 cout<<*it,flag=0;//注意格式最后一个输出后无空格; 26 else cout<<' '<<*it; 27 } 28 cout<<endl; 29 se.clear(); 30 } 31 return 0; 32 }
D:HDU - 1263
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int MAXN=1e5+10; 4 const int INF=0x3f3f3f3f; 5 map<string,map<string,int> >ma; 6 int main() 7 { 8 int T; 9 scanf("%d",&T); 10 while(T--) 11 { 12 int n; 13 scanf("%d",&n); 14 string name,place; 15 int num; 16 for(int i=0;i<n;i++){ 17 cin>>name>>place>>num; 18 ma[place][name]+=num; 19 } 20 map<string,map<string,int> >::iterator it; 21 for(it = ma.begin();it != ma.end();it++){ 22 cout<<it->first<<endl; 23 map<string ,int >::iterator it2; 24 for(it2 = it->second.begin(); it2!=it->second.end(); it2++){ 25 cout<<" |----"<<it2->first<<'('<<it2->second<<')'<<endl;; 26 } 27 it->second.clear(); 28 } 29 ma.clear(); 30 if(T!=0) cout<<endl; 31 } 32 return 0; 33 } 34 //guangdong 35 // |----
E-HDU1004
1 #include<string> 2 #include<iostream> 3 #include<map> 4 #include<string> 5 using namespace std; 6 map<string,int>ma; 7 string s,ans; 8 int main() 9 { 10 int n; 11 while(scanf("%d",&n)!=EOF&&n) 12 { 13 string s; 14 for(int i=0;i<n;i++){ 15 cin>>s; 16 ma[s]++; 17 } 18 int num=0; 19 20 for(map<string,int>::iterator it=ma.begin();it!=ma.end();it++) 21 { 22 s=it->first; 23 if(ma[s]>num) { 24 ans=s; 25 num=ma[s]; 26 } 27 } 28 cout<<ans<<endl; 29 ma.clear(); 30 } 31 32 33 return 0; 34 }
F-HDU 1251
1 #include<stdio.h> 2 #include<string.h> 3 #include<map> 4 #include<string> 5 using namespace std; 6 map<string,int>ma; 7 int main() 8 { 9 char s[10]; 10 while(gets(s)) 11 { 12 int x=strlen(s); 13 if(x==0) 14 break; 15 for(int i=x-1;i>=0;i--) 16 { 17 ma[s]++;s[i]='