蒟蒻20分WA求调

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

hermione_wqx @ 2024-07-26 11:10:34

#include<bits/stdc++.h>
using namespace std;
int main() {
    string name, bname;
    int c, bc, m, bm, y, by;
    int n = 0;
    cin >> n;
    cin >> name >> c >> m >> y;
    for (int i = 1; i < n; i++) {
        cin >> bname >> bc >> bm >> by;
        if (bc + bm + by > c + m + y) {
            c = bc;
            m = bm;
            y = by;
            bname = name;
        }
    }
    cout << name << ' ' << c << ' ' << m << ' ' << y;
    return 0;
}

by goIdie @ 2024-07-26 11:14:14

第15行应为

name = bname;

求关


by haimingbei @ 2024-07-26 11:14:58

@goIdie 你这好像啥也没改啊


by goIdie @ 2024-07-26 11:15:57

@haimingbei ,改了啊


by haimingbei @ 2024-07-26 11:16:39

@hermione_wqx 用结构体和sort快排就很简单


by haimingbei @ 2024-07-26 11:17:47

@goIdie 没看到(当我没说)


by hermione_wqx @ 2024-07-26 11:18:26

@goIdie @haimingbei 谢谢两位大佬


by hermione_wqx @ 2024-07-26 11:23:50

@goIdie 已AC


by strin2024 @ 2024-08-01 20:51:06

题解

#include<>
using namespace ——;
struct stu{
    string na;
    int c,m,e,s;
}st[];
bool cmp(stu a,stu b){
    return a.s>b.s;
}
int main(){
    int n,t=1;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>st[i].na>>st[i].c>>st[i].m>>st[i].e;
        st[i].s=st[i].c + st[i].m + st[i].e;
        if(st[i].s>st[t].s)  t=i;
    }
    cout<<st[t].na<<' '<<st[t].c<<' '<<st[t].m<<' '<<st[t].e;
    return 0;
} 

此题解被做手脚,一 run 直接 CE

广告

可以点关注吗?
| |
v v
我是strin!


|