1012~1014、1019~1021 、1061、1049、1066 、1178、1108、1030 、1071、1597。
1004:是acm的一道比賽題目,可以使用STL,或者string類。stl代碼比較簡潔而且時間內存都較少具體如下:
TIME:0ms
MEM: 364K
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
int n;
while(cin>>n && n)
{
string temp;
map<string,int> balloon;
for(int i=0;i<n;i++)
{
cin>>temp;
balloon[temp]++;
}
map<string,int>::iterator i=balloon.begin(),max=balloon.begin();
for(;i!=balloon.end();i++)
{
if(i->second>max->second)
max = i;
}
cout<<max->first<<endl;
}
return 0;
}
當然也可以使用結構體定義一個氣球類:包括顏色和數量。
TIME:0ms
MEM:372K
#include <iostream>
#include <string>
using namespace std;
struct balloon
{
string color;
int num;
}ballo[1000];
int main()
{
int N;
string temp;
while(cin>>N &&N)
{
int len = 0;
int max[2] = {0,0};//個數 數目
bool flag = false;
for(int i=0;i<N;i++)
{
cin>>temp;
flag = false;
for(int j=0;j<len;j++)
{
if(temp == ballo[j].color)
{
ballo[j].num++;
flag = true;
if(ballo[j].num > max[0])
{
max[0] = ballo[j].num;
max[1] = j;
}
}
}
if(flag == false)//沒有
{
ballo[len].color=temp;
ballo[len].num=1;
len++;
}
}
cout<<ballo[max[1]].color<<endl;
}
return 0;
}