摘要

题目链接 难度等级 完成状态 完成分数 最后编辑时间 需要注意
Let the Balloon Rise ★☆☆☆☆ 答案正确 100 2015-02-06 11:06:55

题意

给一组字符串,求出现最多的一个。

题解

  • 扔到multiset里(不了解STL请戳CodeVS/1075)/hash一下,然后count一下,记个max。

代码

1004.cpp代码已折叠
展开折叠内容
显示/移除行号
  1. #include<cstdio>
  2. #include<set>
  3. #include<string>
  4. #include<iostream>
  5. #define F(i,n) for(int i=1;i<=n;++i)
  6. using namespace std;
  7. multiset<string> S;
  8. int main()
  9. {
  10. while(1)
  11. {
  12. int n,ans=0;
  13. cin>>n;
  14. if(!n)
  15. return 0;
  16. string s,ansS;
  17. F(i,n)
  18. {
  19. cin>>s;
  20. S.insert(s);
  21. if(S.count(s)>ans)
  22. {
  23. ans=S.count(s);
  24. ansS=s;
  25. }
  26. }
  27. cout<<ansS<<endl;
  28. }
  29. }

著作权声明[编辑]

关于[编辑]