#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main()
{
int t;
while(cin>>t)
{
if(t==0) break;
string color[1001];
for(int i=0;i<t;i++)
{
cin>>color[i];
}
sort(color,color+t);
int cnt=1,max=0;
string s=color[0];
for(int j=0;j<t-1;j++)
{
if(color[j]==color[j+1]) cnt++;
else cnt=1;
if(cnt>max)
{
s=color[j];
max=cnt;
}
}
cout<<s<<endl;
}
return 0;
}这道题首先定义了string的数组,用来存储多个字符串。
这个数组的使用方法与int 数组相同。
这道题的思路是先用string数组输入,然后进行sort排序,使得相同的字符串连在一起,然后进行比较计数。
本文探讨了一段使用C++实现的代码,该代码通过定义字符串数组存储多个字符串,然后对其进行排序和计数操作。文章详细介绍了如何在数组中存储字符串,以及如何利用sort函数对字符串进行排序,最后通过计数来找出连续重复次数最多的字符串。
976

被折叠的 条评论
为什么被折叠?



