谁能教教我这个代码怎么挂了?/?

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

已注销tJ4ESCeB @ 2020-09-08 20:09:03

#include <bits/stdc++.h>
using namespace std;
struct study{
    string name;
    int chinese, math, english;
}a, ans;
int n;
int main() {
    cin>>n;
    for(int i=1; i<=n; i++) {
        cin>>a.name>>a.chinese>>a.math>>a.english;
        if(a.chinese+a.math+a.english>ans.chinese+ans.math+ans.english)
        ans=a;
    }
    cout<<ans.name<<" "<<ans.chinese<<ans.math<<" "<<ans.english<<endl;
    return 0;
}

by Smile_Cindy @ 2020-09-08 20:09:47

cout<<ans.name<<" "<<ans.chinese<<ans.math<<" "<<ans.english<<endl;

by Smile_Cindy @ 2020-09-08 20:09:56

@hutianyu


by 已注销tJ4ESCeB @ 2020-09-08 20:10:53

@Alpha ????


by 已注销tJ4ESCeB @ 2020-09-08 20:11:42

你逗我?


by SIXIANG32 @ 2020-09-08 20:12:03

@hutianyu 少了个空格吧


by Remake_ @ 2020-09-08 20:12:54

测试了一下您的代码才发现恶臭的样例


by Smile_Cindy @ 2020-09-08 20:17:16

@hutianyu

应该为

cout<<ans.name<<" "<<ans.chinese<<' '<<ans.math<<" "<<ans.english<<endl;

眼睛不需要可以捐给有需要的人。


|