标签:style blog color os io for ar div
map 水题
1 #include <map> 2 #include <cstdio> 3 #include <iostream> 4 #include <string.h> 5 #include <cstring> 6 #include <string> 7 using namespace std; 8 map<string,int > a; 9 map<string,string> b; 10 11 int main(){ 12 //freopen("test.txt","r",stdin); 13 int n,m; 14 char s1[85],s2[85]; 15 scanf("%d",&n); 16 getchar(); 17 for(int i=0;i<n;i++){ 18 cin.getline(s1,85,‘\n‘); 19 cin.getline(s2,85,‘\n‘); 20 a[s1]=1; 21 b[s1]=s2; 22 } 23 scanf("%d",&m); 24 getchar(); 25 int max1=0,count1=0; 26 string st; 27 for(int i=0;i<m;i++){ 28 cin.getline(s1,85,‘\n‘); 29 if(a[s1]==0)continue; 30 a[s1]++; 31 if(a[s1]==max1)count1++; 32 if(a[s1]>max1){ 33 max1=a[s1]; 34 st=b[s1]; 35 count1=1; 36 } 37 } 38 if(count1==1){ 39 cout<<st<<endl; 40 } 41 else cout<<"tie"<<endl; 42 43 }
#include <map>
#include <cstdio>
#include <iostream>
#include <string.h>
#include <cstring>
#include <string>
using namespace std;
map<string,int > a;
map<string,string> b;
int main(){
freopen("test.txt","r",stdin);
int n,m;
char s1[85],s2[85];
scanf("%d\n",&n);
//getchar();
for(int i=0;i<n;i++){
cin.getline(s1,85,‘\n‘);
cin.getline(s2,85,‘\n‘);
a[s1]=1;
b[s1]=s2;
}
scanf("%d\n",&m);
//getchar();
int max1=0,count1=0;
string st;
for(int i=0;i<m;i++){
cin.getline(s1,85,‘\n‘);
if(a[s1]==0)continue;
a[s1]++;
if(a[s1]==max1)count1++;
if(a[s1]>max1){
max1=a[s1];
st=b[s1];
count1=1;
}
}
if(count1==1){
cout<<st<<endl;
}
else cout<<"tie"<<endl;
}
标签:style blog color os io for ar div
原文地址:http://www.cnblogs.com/Mr-Xu-JH/p/3884475.html