每日一题 第八期 洛谷 宇宙总统

这篇文章介绍了如何通过编程(C++)解决一个关于宇宙总统竞选的问题,涉及输入竞选人数和候选人票数,然后对票数进行排序以确定胜者。
摘要由CSDN通过智能技术生成

宇宙总统

题目描述

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

输入格式

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

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

输出格式

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

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

样例 #1

样例输入 #1

5
98765
12365
87954
1022356
985678

样例输出 #1

4
1022356

提示

票数可能会很大,可能会到 100 100 100 位数字。

1 ≤ n ≤ 20 1 \leq n \leq 20 1n20

AC代码:

#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<string>
#include<bitset>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<numeric>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef pair<int, int>PII;
const int N=3e5+10;
const int MOD=998244353;
const int INF=0X3F3F3F3F;
const int dx[]={-1,1,0,0,-1,-1,+1,+1};
const int dy[]={0,0,-1,1,-1,+1,-1,+1};
const int M = 1e6 + 10;

struct hou{
	string a;
	int b;
	bool operator <(const  hou & u) const 
	{
		if(a.size() == u.a.size()) {
			return a < u.a;
		}
		else return a.size() < u.a.size();
	}
}s[1010];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i ++)
	{
		cin >> s[i].a;
		s[i].b = i;
	}
	sort(s + 1, s + 1 + n);
	cout <<s[n].b << endl << s[n].a << endl;
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值