P1781 宇宙总统

P1781 宇宙总统

题目描述

地球历公元 6036 年,全宇宙准备竞选一个最贤能的人当总统,共有 nn 个非凡拔尖的人竞选总统,现在票数已经统计完毕,请你算出谁能够当上总统。

输入格式

第一行为一个整数 nn,代表竞选总统的人数。

接下来有 nn 行,分别为第一个候选人到第 nn 个候选人的票数。

输出格式

共两行,第一行是一个整数 mm,为当上总统的人的号数。

第二行是当上总统的人的选票。

输入输出样例

输入

5
98765
12365
87954
1022356
985678

输出

4
1022356

解题思路:

简单的string类型比较即可。

#include<iostream>
#include<string>
using namespace std;

int main()
{
	int n;
	cin >> n;
	string max;
	int cnt;
	int all = n;
	while (n--)
	{
		string str;
		cin >> str;
		int len = str.length();
		int lenmax = max.length();
		if (len > lenmax || (lenmax == len&&max < str))
		{
			max = str;
			cnt = all - n;
		}
	}
	cout << cnt << "\n" << max << endl;
	return 0;
}

 

posted @ 2020-02-20 11:32  Hu_YaYa  阅读(170)  评论(0)    收藏  举报