荔园在线

荔园之美,在春之萌芽,在夏之绽放,在秋之收获,在冬之沉淀

[回到开始] [上一篇][下一篇]


发信人: alec (AlecMonkeyKing), 信区: ACMICPC
标  题: The code of the first problem in Sunny Cup
发信站: 荔园晨风BBS站 (Sun May 23 10:53:56 2004), 站内信件

#include <iostream>
#include <string>

using namespace std;
const int maxn=1000;

string save[maxn],save1[maxn];
int sum[maxn];
int m;

void add(string st)
{
  int i;
  for (i=0;i<m;i++)
  {
    if (save[i]==st)
      return;
  }
  save[m++]=st;
}

int check(string st)
{
  int i;
  for (i=0;i<m;i++)
  {
    if (st==save[i])
    {
      return i;
    }
  }
  return -1;
}
int main()
{
  int k,i,w,max,t;
  string st;
  cin>>k;
  cin.ignore(100,'\n');
  while (k>0)
  {
    m=0;
    memset (sum,0,sizeof(sum));
    for (i=0;i<k;i++)
    {
      getline(cin,st);
      save1[i]=st;
      add(st);
    }
    for (i=0;i<k;i++)
    {
      w=check(save1[i]);
      sum[w]++;
    }
    max=-1;
    for (i=0;i<m;i++)
    {
      if (max<sum[w])
      {
        max=sum[w];
        t=w;
      }
    }
    cout<<save[t]<<endl;
    cin>>k;
    cin.ignore(100,'\n');
  }
  return 0;
}

--
           Computer Science is no more about computers
               than Astronomy is about telescopes.
                                            -- E. W. Dijkstra
Alec

※ 来源:·荔园晨风BBS站 bbs.szu.edu.cn·[FROM: 210.21.224.233]


[回到开始] [上一篇][下一篇]

荔园在线首页 友情链接:深圳大学 深大招生 荔园晨风BBS S-Term软件 网络书店