您的位置:首页 > 其它

hdu 1004 Let the Balloon Rise

2012-08-11 17:41 435 查看
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
="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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: