CWJ1029 @ 2020-05-18 11:09:59
#include <cstdio>
#include <algorithm>
using namespace std;
struct student
{
int C , M , E , A , I;
char N[];
void read(int x)
{
scanf("%s %d%d%d" , &N , &C , &M , &E);
A = C + M + E;
I = x;
}
}a[1005];
bool cmp(student ac , student wa)
{
if (ac.A != wa.A) return ac.A > wa.A;
else return ac.I < wa.I;
}
int n;
int main()
{
scanf("%d" , &n);
for (int i = 1; i <= n; i++) a[i].read(i);
sort(a + 1 , a + n + 1 , cmp);
printf("%s %d %d %d" , a[1].N , a[1].C , a[1].M , a[1].E);
return 0;
}
by iMya_nlgau @ 2020-05-18 11:15:56
scanf("%s %d%d%d" , &N , &C , &M , &E);
N前面不应该有取地址符
by iMya_nlgau @ 2020-05-18 11:16:07
@CaiWeiJie20101029
by pocafup @ 2020-05-18 11:17:39
N用string不好吗。。。我改成string就A了
by iMya_nlgau @ 2020-05-18 11:20:54
还有 把%s
和%d
之间的空格去掉
by CWJ1029 @ 2020-05-18 14:28:12
@Sapphire6575737973 还是一样的
by iMya_nlgau @ 2020-05-18 14:33:11
@CaiWeiJie20101029
我又给你改了改,把char N[]
改成char N[10]
就AC了,别问我为什么
#include <cstdio>
#include <algorithm>
using namespace std;
struct student
{
int C , M , E , A , I;
char N[10];
void read(int x)
{
scanf("%s%d%d%d" , N , &C , &M , &E);
A = C + M + E;
I = x;
}
}a[1005];
bool cmp(student ac , student wa)
{
if (ac.A != wa.A) return ac.A > wa.A;
else return ac.I < wa.I;
}
int n;
int main()
{
scanf("%d" , &n);
for (int i = 1; i <= n; i++) a[i].read(i);
sort(a + 1 , a + n + 1 , cmp);
printf("%s %d %d %d" , a[1].N , a[1].C , a[1].M , a[1].E);
return 0;
}