标准答案(用sort+string) 先看长度,再用string的比较 12345678910111213141516171819202122232425262728#include<bits/stdc++.h>using namespace std;struct president{ string price; int n;}a[100];int m;bool cmp(president x,president y);int main(){ cin>>m; for(int i=1;i<=m;i++) { cin>>a[i].price; a[i].n=i; } sort(a+1,a+m+1,cmp); cout<<a[1].n<<endl<<a[1].price;}bool cmp(president x,president y){ if(x.price.length()!=y.price.length()) return x.price.length()>y.price.length(); else return x.price>y.price;}