HDU-1004(基础题)

思想;用一个数组保存每个字符串出现的次数;其中为了能够用 该时数组与前边数组比较,设置一个结构数组能够寸字符串就 ok了;
AC代码;

 #include <iostream>
 #include <cstdio>
 #include <cstring>
 #include <map>
 #include <algorithm>
 #include <sstream>
 #include <set>
 #include <string>
 #include <stack>
 #include <vector>
using namespace std;
const int N = 10000;
typedef long long LL;
const int inf = 0x3f3f3f3f;
struct str{
   char c[N];
}str[N];
int main()
{
 LL t;
 LL num[N];
 while(cin>>t&&t)
 {
     getchar();
     for(int i=0;i<t;i++)
     {
        cin>>str[i].c;
     }
     for(int i=0;i<t;i++)
     {
         int m=1;
         for(int j=i+1;j<t;j++)
         if(!strcmp(str[i].c,str[j].c))
            m++;
         num[i]=m;
     }
     LL maxn=num[0];
     LL k=0;
     for(int j=1;j <t;j++)
          if(maxn<num[j])
          {
            maxn=num[j];
            k=j;
          }
    cout<<str[k].c<<endl;
 }
 return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值