hdoj 1004 寻找气球颜色出现最多次数

论坛 期权论坛 脚本     
匿名技术用户   2020-12-27 08:23   11   0
<h1 style="color: rgb(26, 92, 200); text-align: center; font-family: 'Times New Roman';">让气球上升</h1><span style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;"><strong><span style="font-family: Arial; font-size: 12px; color: green;">时间限制:2000/1000(Java /其他)内存限制女士:65536/32768 K(Java /其他)
总提交(s):89080接受提交(s):33715
</span></strong></span><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-812ba10ad0dd6a502e1e3972fd808747.png) 0% 100% no-repeat transparent;">问题描述</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-69c0df5f59e97cf4871035fc7af7760c.png) repeat-y;">比赛一次又一次! 是多么的兴奋看到气球漂浮。 但是要告诉你一个秘密,法官的最喜欢的时间是猜测最受欢迎的问题。 当比赛结束时,他们将计算每一种颜色的气球,找到结果。

今年,他们决定离开这个可爱的工作给你。
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-c6f4487db520308f8b73ecdf5ccd5938.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-812ba10ad0dd6a502e1e3972fd808747.png) 0% 100% no-repeat transparent;">输入</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-69c0df5f59e97cf4871035fc7af7760c.png) repeat-y;">输入包含多个测试用例。 每个测试用例开始于一个数字(0 < N < = 1000),气球分布式的总数。 接下来的N行包含一个颜色。 的颜色的气球是一个字符串15小写字母。

一个测试用例与N = 0终止输入和这个测试用例不是要处理。
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-c6f4487db520308f8b73ecdf5ccd5938.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-812ba10ad0dd6a502e1e3972fd808747.png) 0% 100% no-repeat transparent;">输出</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-69c0df5f59e97cf4871035fc7af7760c.png) repeat-y;">对于每个案例,印刷气球的颜色最受欢迎的问题在一行。 它是保证每个测试用例有一个独特的解决方案。
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-c6f4487db520308f8b73ecdf5ccd5938.png) 0% 0% no-repeat;"> </div><br style="font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center;" /><div class="panel_title" align="left" style="height: 38px; padding: 0px 14px; color: rgb(124, 169, 237); font-size: 18px; font-family: Arial; font-weight: bold; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-812ba10ad0dd6a502e1e3972fd808747.png) 0% 100% no-repeat transparent;">样例输入</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; backgroundnull:url(https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-69c0df5f59e97cf4871035fc7af7760c.png) repeat-y;"><pre style="word-wrap: break-word; white-space: pre-wrap; margin-top: 0px; margin-bottom: 0px;"><div style="font-family: 'Courier New', Courier, monospace;">5<pre name="code" class="cpp">
绿色红色的蓝色的红色的红色的3粉红色的橙色粉红色的0


样例输出
红色的 粉红色的

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;

int main()
{  
    int flag;
    int maxn;
 int n,i,j,d=0;
 char s[1001][16];
 int a[1001];
 while(scanf("%d",&n)&&n!=0)
 {
  for(i=0;i<n;i++)
  {
   scanf("%s",s[i]);
  }
  flag=0;
  maxn=0;
  for(i=0;i<n;i++)
  {   
     a[i]=1;  //因为最少 
   for(j=n-1;j>i;j--)//从右往左进行比较,将其出现次数不断累加 
   {  
     if(strcmp(s[i],s[j])==0)//类似于冒泡排序(即不重复的比较所有的数) 
    {  
      a[i]+=1; 
       }
   }
   if(maxn<a[i])
      {
       maxn=a[i];//又取了一个值,让最大值永远等于所取变量 
       flag=i;   //找了一个标志位,不断记录出现次数最多的位数 
   }
        }  
 printf("%s\n",s[flag]);
 }
return 0;


总结:1、学会使用标志位!
2、如何寻找字符串出现次数,并进行累计,比较

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP