题目大意
给出m个数,第i个数的编号为i,试求最大的数的编号及其数值(以字符串形式输出即可)
自定义排序方法cmp
bool cmp(person x, person y)
{
if (x.score.size() == y.score.size())
return x.score > y.score;
else
return x.score.size() > y.score.size();
}
由于数据超过100位,而long long最大值为2^63 - 1, unsigned long long最大值为2^64 - 1,故而只能以字符串形式存储输入数据。
代码如下:
// 票数可能会很大,可能会到100位数字
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int maxn = 25;
struct person
{
int id;
string score;
};
struct person s[maxn];
bool cmp(person x, person y)
{
if (x.score.size() == y.score.size())
return x.score > y.score;
else
return x.score.size() > y.score.size();
}
int main()
{
int m;
while (cin >> m)
{
for (int i = 0; i <