Let the Balloon Rise 为什么错了? 5
//---------------------------------------------------------------------------#include...
//---------------------------------------------------------------------------
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string ballon[1010];
for(int n;cin>>n&&n!=0;)
{
for(int i=0;i<n;++i)
cin>>ballon[i];
sort(ballon,ballon+n);
int sum1=1,sum2=0,max;
for(int i=0;i<n-1;++i)
{
if(ballon[i]==ballon[i+1])
{sum1++;
if(sum1>sum2) max=i+1;
}
else { sum2=sum1;sum1=1;}
}
cout<<ballon[max]<<endl;
}
return 0;
}
//--------------------------------------------------------------------------- 展开
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main()
{
string ballon[1010];
for(int n;cin>>n&&n!=0;)
{
for(int i=0;i<n;++i)
cin>>ballon[i];
sort(ballon,ballon+n);
int sum1=1,sum2=0,max;
for(int i=0;i<n-1;++i)
{
if(ballon[i]==ballon[i+1])
{sum1++;
if(sum1>sum2) max=i+1;
}
else { sum2=sum1;sum1=1;}
}
cout<<ballon[max]<<endl;
}
return 0;
}
//--------------------------------------------------------------------------- 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询