luosw @ 2020-03-09 14:00:14
附上我的代码
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int n;
struct pupil{
string m;
int c,ma,e,s,no;
};
bool cmp(pupil x,pupil y){
if(x.s!=y.s) return x.s>y.s;
else return x.no<y.no;
}
pupil a[1000];
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
a[i].no=i;
scanf("%s%d%d%d",&a[i].m,&a[i].c,&a[i].ma,&a[i].e);
a[i].s=a[i].c+a[i].ma+a[i].e;
}
sort(a,a+n-1,cmp);
printf("%s %d %d %d\n",a[0].m,a[0].c,a[0].ma,a[0].e);
return 0;
}
希望大家帮忙!
by HearTheWindSing @ 2020-03-09 14:04:23
@luosiwei string类型不能用scanf输入
by luosw @ 2020-03-09 14:06:33
@wangyxhaha 为什么不可以呢?那C语言是怎么输入的?
by HearTheWindSing @ 2020-03-09 14:08:22
@luosiwei c没有string,c是用字符数组,字符数组可以用scanf
by HearTheWindSing @ 2020-03-09 14:09:19
scanf是从c继承过来的,所以不支持string,要输入string就用cin
by luosw @ 2020-03-09 14:11:27
@wangyxhaha 明白了,用cin和cout问题就解决了,谢谢大佬!
by luosw @ 2020-03-09 14:12:40
我还是更喜欢用scanf和printf