2417: 【普及-】【P1781】宇宙总统

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:9 解决:7

题目描述

地球历公元 6036 年,全宇宙准备竞选一个最贤能的人当总统,共有 lns="http://www.w3.org/1998/Math/MathML"> 个非凡拔尖的人竞选总统,现在票数已经统计完毕,请你算出谁能够当上总统。

输入

第一行为一个整数 lns="http://www.w3.org/1998/Math/MathML">,代表竞选总统的人数。

接下来有 lns="http://www.w3.org/1998/Math/MathML"> 行,分别为第一个候选人到第 lns="http://www.w3.org/1998/Math/MathML"> 个候选人的票数。

输出

共两行,第一行是一个整数 lns="http://www.w3.org/1998/Math/MathML">,为当上总统的人的号数。

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

样例输入 复制

5
98765
12365
87954
1022356
985678

样例输出 复制

4
1022356

提示

票数可能会很大,可能会到 lns="http://www.w3.org/1998/Math/MathML">100 位数字。

lns="http://www.w3.org/1998/Math/MathML">120

#include<bits/stdc++.h>
using namespace std;
int const MAXN=30;
struct node {
	string x; //票数
	int num;  //候选人编号 
}s[MAXN];
bool cmp(node a,node b) {
	if (a.x.length()!=b.x.length())
	    return a.x.length() >b.x.length();  //a比b位数多时a在前面
	return a.x>b.x;  //位数相同,但a字典序排列比b大 
}
int n;
int main(){
    cin>>n;
    for (int i=0;i<n;i++) {
    	cin>>s[i].x;
    	s[i].num=i+1;
	}
    sort(s,s+n,cmp);
    cout<<s[0].num<<endl<<s[0].x<<endl;
	return 0;
}