AC WA or PE

来源:互联网 发布:都市年轻人养猫数据 编辑:程序博客网 时间:2024/04/27 18:15

 #include <iostream>
#include <string>
using namespace std;

struct Infor
{
 string str;
 int  nFre;
};


int main()
{
 int    i, j, k = 0;
 string   strWord;
 struct Infor array[100];
 
 cin >> i;
 
 while (0 != i)
 {
  int   nSum = 0;
  for (j = 0; j < i; j++)    //得到输入的次数
  {
   cin >> strWord;
   k = 0;
   bool bRet = false;
   
   for (k = 0; k < nSum; k++)
   {
    if (array[k].str == strWord)
    {
     array[k].nFre += 1;
     bRet = true;
     break;
    }     
   }
   
   if (!bRet)
   {
    array[nSum].str = strWord;
    array[nSum].nFre = 1;
    nSum++;
   }
   
  }
  
  int  temp = array[0].nFre;
  strWord = array[0].str;

  for (i = 1; i < nSum; i++)
  {
   if (temp < array[i].nFre)
   {
    temp = array[i].nFre;
    strWord = array[i].str;
   }
  }
  
  cout << strWord << endl;
  
  cin >> i;
 }
 
 return 0;
}