题目描述
地球历公元6036年,全宇宙准备竞选一个最贤能的人当总统,共有n个非凡拔尖的人竞选总统,现在票数已经统计完毕,请你算出谁能够当上总统。
输入格式
第一行为一个整数n,代表竞选总统的人数。
接下来有n行,分别为第一个候选人到第n个候选人的票数。
输出格式
共两行,第一行是一个整数m,为当上总统的人的号数。
第二行是当上总统的人的选票。
输出样例
5
98765
12365
87954
1022356
985678
输出
4
1022356
说明/提示
票数可能会很大,可能会到100位数字。
n<=20
100位数字显然是要我们转化成字符串来做!
string 可以直接比较大小,但是要注意位数!!!!
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<algorithm>
#include<iostream>
using namespace std;
typedef struct
{
int id;
string score;
}Node;
bool cmp(Node a,Node b)
{
if(a.score.length()!=b.score.length())
return a.score.length()>b.score.length();
else
return a.score>b.score;
}
Node node[25];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>node[i].score;
node[i].id=i+1;
}
sort(node,node+n,cmp);
cout<<node[0].id<<endl;
cout<<node[0].score<<endl;
return 0;
}