帮本蒟蒻debug

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

shangyuang @ 2022-06-30 19:48:44

code:

#include<bits/stdc++.h>
using namespace std;
int n,a,max1=INT_MIN,io;
struct student{
    string name;
    int yw;
    int sx;
    int yy;

}s[1001];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        getline(cin,s[i].name);
        cin>>s[i].yw>>s[i].sx>>s[i].yy;

    }
    for(int i=n;i>=1;i--){
         if(max1<=s[i].yw+s[i].sx+s[i].yy){
             io=i;
             max1=s[i].yw+s[i].sx+s[i].yy;
        }
    }
        cout<<s[io].name<<' '<<s[io].yw<<' '<<s[io].sx<<' '<<s[io].yy;

        return 0;
}


by Snoozing_QAQ @ 2022-06-30 19:52:25

思路讲下


by hex2007 @ 2022-06-30 19:53:53

getline直接输入了一行,其中包括了成绩

应该用cin来输入姓名


by hex2007 @ 2022-06-30 19:54:22

@shangyuang


by Snoozing_QAQ @ 2022-06-30 19:55:00

把 getline 那行给吞掉就AC了


by Snoozing_QAQ @ 2022-06-30 19:58:49

#include<bits/stdc++.h>
using namespace std;
int n,max1 = INT_MIN,io;
struct student {
    string name;
    int yw;
    int sx;
    int yy;
} s[1001];
int main() {
    cin >> n;
    for(int i = 1; i<=n; i++)
        cin >> s[i].name >> s[i].yw >> s[i].sx >> s[i].yy;
    for(int i = n; i>=1; i--)
        if(max1<=s[i].yw+s[i].sx+s[i].yy) {
            io=i;
            max1=s[i].yw+s[i].sx+s[i].yy;
        }
    cout << s[io].name << " " << s[io].yw << " " << s[io].sx << " " << s[io].yy;
    return 0;
}

by Snoozing_QAQ @ 2022-06-30 19:58:59

这样的


by Snoozing_QAQ @ 2022-06-30 19:59:36

@shangyuang


by shangyuang @ 2022-06-30 20:46:56

@wushangheng2 哦哦 thank you


by shangyuang @ 2022-06-30 20:52:44

谢谢大佬们


by shangyuang @ 2022-06-30 20:52:57

@hex2007


| 下一页