样例过了,全wa

P5740 【深基7.例9】最厉害的学生

ansan @ 2023-12-01 19:52:48


#include<bits/stdc++.h>
#include<cstring>
#include<stdio.h>
using namespace std;
int main(){
    int n, i, j, k, max = -1, a, b, c;
    char s[300], str[100], str1[100];
    scanf("%d", &n);
    getchar();
    while(n--){
        fgets(s, sizeof(s), stdin);
        sscanf(s, "%s %d %d %d", str, &a, &b, &c);
        if(a + b + c > max){
            max = a + b +c;
            i = a; j = b; k = c;
            strcpy(str1, str);
        }
    }
    printf("%s %d %d %d", str1, i, j, k);
    return 0;
}

by penguin_is_cool @ 2023-12-07 07:21:28

@ansan 请问你会用数组么?


by xjj110626 @ 2023-12-24 16:40:59

@ansan 代码:

include<bits/stdc++.h>

using namespace std; string p; int o,i,u,y=-1; struct student{ string n; int c,m,e,s; }q; int main() {

int n;
cin>>n;
for(int j=0;j<n;j++)
{
    cin>>q.n>>q.c>>q.m>>q.e;
    q.s=q.c+q.m+q.e;
    if(q.s>y)
    {
        y=q.s;
        p=q.n;
        o=q.c;
        i=q.m;
        u=q.e;
    }
} 
cout<<p<<' '<<o<<' '<<i<<' '<<u;
return 0;

}


by ansan @ 2023-12-25 12:28:56

@xjj110626 谢谢大佬,之前想错了,懂了懂了,已关


by xjj110626 @ 2023-12-25 21:03:40

@ansan 没事没事!


|