Let the Balloon Rise

<h1 style="color: rgb(26, 92, 200); text-align: center; font-family: 'Times New Roman';">Let the Balloon Rise</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;">Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 78809    Accepted Submission(s): 29588
</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; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Problem Description</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.

This year, they decide to leave this lovely job to you. 
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.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; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Input</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters.

A test case with N = 0 terminates the input and this test case is not to be processed.
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.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; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Output</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.png) repeat-y;">For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case.
</div><div class="panel_bottom" style="height: auto; margin: 0px; font-family: 'Times New Roman';font-size:14px; text-align: -webkit-center; background: url(http://acm.hdu.edu.cn/images/panel-bottom.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; background: url(http://acm.hdu.edu.cn/images/panel-title.png) 0% 100% no-repeat transparent;">Sample Input</div><div class="panel_content" style="height: auto; margin: 0px; padding: 0px 20px; font-size: 14px; font-family: 'Times New Roman'; background: url(http://acm.hdu.edu.cn/images/panel-content.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
green
red
blue
red
red
3
pink
orange
pink
0</div>
 

Sample Output
  
  
red pink
 

#include <cstdio>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
int compare(const string &a,const string &b)
{
	return a>b;
}
int main()
{
     int n,max=1,now=1;
	 string a[1010];
	 while (scanf("%d",&n)&&n)
	 {
         for (int i=0;i<n;i++)
         {
			 cin>>a[i];//读取字符串存入字符数组!
         }
		// getchar();
		 sort(a,a+n,compare);//排序
		/* for (i=0;i<n;i++)
		 {
			 printf("%s ",a[i]);
		 }*/
		 string c=a[0];
		 for (int j=1;j<n;j++)
		 {
			 if (a[j]==a[j-1])
			 {
                 now++;
			 }
			 else
			 {
                 if (now>max)
                 {
					 max=now;
					 c=a[j-1];
                 }
				 now=1;
			 }
		 }
       if (now>max)
       {
		   c=a[j-1];
       }//为什么最后还要比一下呢?因为上文写的程序只能处理倒数第二次的字符串,所以最后次比较要记进去
	  cout<<c<<endl;
	 }
}//感觉这一题让我增长了不少见识!首先他是一个比较字符串的程序,本来我打算使用C语言中结构体进行储存字符串,后来发现可以用C++
//的string[]数组进行储存,这就很方便了!但是一定要注意,string类型的读取与输出要用到数据流的方式进行,并非scanf,printf!



                
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值