P1781 宇宙总统 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
当时写cmp的时候没想到直接让string类型进行比较
cpp
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
const int N = 2e7+10,M = 1e3+10;
int a[N],pre[N];
int chi[N],math[N],eng[N],id[N],b[N];
struct zongtong
{
int id;
string sum;
};
bool cmp(zongtong a,zongtong b)
{
if(a.sum.size()>b.sum.size())return 1;
else if(a.sum.size()==b.sum.size()&&a.sum>b.sum)return 1;
else return 0;
}
signed main()
{
std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin>>n;
zongtong z[30];
for(int i=1;i<=n;i++)
{
cin>>z[i].sum;
z[i].id = i;
}
sort(z+1,z+1+n,cmp);
cout<<z[1].id<<endl<<z[1].sum;
return 0;
}