标签:style blog color io os for strong sp div
题意
给出n个字符串,输出出现次数最多的那个
分析
存下字符串后排序,再统计,输出
Accepted Code
1 /* 2 PROBLEM:hdu1004 3 AUTHER:Nicole Lam 4 MEMO:水题 5 */ 6 7 #include<iostream> 8 #include<cstring> 9 #include<string> 10 #include<algorithm> 11 using namespace std; 12 13 int main() 14 { 15 int n; 16 cin>>n; 17 while (n!=0) 18 { 19 string a[1010]; 20 int num[1010]; 21 for (int i=1;i<=n;i++) cin>>a[i]; 22 sort(a+1,a+n+1); 23 for (int i=1;i<=n;i++) num[i]=1; 24 int ans=1; 25 for (int i=2;i<=n;i++) 26 { 27 if (a[i]==a[i-1]) num[i]+=num[i-1]; 28 if (num[i]>=num[ans]) ans=i; 29 } 30 cout<<a[ans]<<endl; 31 cin>>n; 32 } 33 return 0; 34 }
水题/hdu 1004 Let the Balloon Rise
标签:style blog color io os for strong sp div
原文地址:http://www.cnblogs.com/NicoleLam/p/4018274.html