现在的位置: 首页 > 综合 > 正文

hdu 1004 Let the Balloon Rise

2013年10月02日 ⁄ 综合 ⁄ 共 498字 ⁄ 字号 评论关闭

http://acm.hdu.edu.cn/showproblem.php?pid=1004

枚举遍历,字符串排序。

#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
	int n;
	int col[1000];
	string s[1010];
	int flag;
	while(cin>>n&&n){
		memset(col,0,sizeof(col));
		for(int i=0;i<n;i++)
		  cin>>s[i];
  		for(int i=0;i<n-1;i++)
  			for(int j=i+1;j<n;j++)
			  	if(s[i]>s[j]) swap(s[i],s[j]);
		string max_color=s[0];
		s[n]="ORZ";
		int cont=1,max=0;
		for(int i=1;i<n+1;i++){
			if(s[i]==s[i-1]) cont++;
			else{
				if(cont>max){
					max=cont;
					max_color=s[i-1];
				}
				cont=1;				
			}
		}
		cout<<max_color<<endl;	  
	}
	return 0;
}

抱歉!评论已关闭.