STL
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<<'\n'; } 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]='\0'; 18 } 19 } 20 while(scanf("%s",s)!=EOF) 21 { 22 printf("%d\n",ma[s]); 23 } 24 25 return 0; 26 }
G-不重复数字 HYSBZ - 2761
1 #include<bits/stdc++.h> 2 using namespace std; 3 map<int ,int >ma; 4 vector<int >ve; 5 int main() 6 { 7 int n; 8 scanf("%d",&n); 9 while(n--) 10 { 11 ma.clear(); 12 int m; 13 scanf("%d",&m); 14 int x; 15 for(int i=0;i<m;i++) 16 { 17 scanf("%d",&x); 18 if(ma[x]==0) 19 { 20 ma[x]++; 21 ve.push_back(x); 22 } 23 24 } 25 for(int i=0;i<ve.size();i++) 26 printf("%d ",ve[i]); 27 printf("\n"); 28 ve.clear(); 29 } 30 return 0; 31 }
I- Three Parts of the Array CodeForces - 1006C
1 #include<bits/stdc++.h> 2 using namespace std; 3 4 const int MAXN= 2e5+10; 5 const int INF=0x3f3f3f3f; 6 int b[MAXN]; 7 set<long long > se; 8 map<long long ,long long> ma; 9 int main() 10 { 11 int n; 12 scanf("%d",&n); 13 for(int i=0;i<n;i++) 14 { 15 scanf("%d",&b[i]); 16 } 17 long long len=0,sum=0; 18 for(int i=0;i<n;i++){ 19 sum+=b[i]; 20 len++; 21 se.insert(sum); 22 ma[sum]=len; 23 } 24 long long ans=0; 25 for(int i=0;i<n;i++){ 26 sum-=b[i]; 27 len--; 28 if(se.count(sum)==1&&ma[sum]+len<=n) 29 { 30 ans=sum; 31 break; 32 } 33 } 34 printf("%lld\n",ans); 35 return 0; 36 }