C++新手:输入流错误 求大佬康康

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

像素旋转 @ 2021-01-31 14:04:13

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
const int N = 1000;
class Student {
public:
    char name[9];
    int chinese;
    int math;
    int english;

    Student() {
        name[0] = '0';
        chinese = 0;
        math = 0;
        english = 0;
        sum = 0;
    };

    int summary() {
        return sum=chinese + math + english;
    }

private:
    int sum;
};
int main(void)
{
    int n;
    cin >> n;
    cin.get();
    Student** stu;
    stu = new Student*[n];
    int* sum = new int[n];
    int max = 0;
    int ans = 0;
    for (auto i = 0; i < n; i++){
        cin >>stu[i]->name>>stu[i]->chinese >> stu[i]->math >> stu[i]->english;
        sum[i]=stu[i]->summary();
        if (max < sum[i]) {
            max = sum[i];
            ans = i;
        }
    }
    cout << stu[ans]->name << " " << stu[ans]->chinese
        << " " << stu[ans]->math << " " << stu[ans]->english << endl;

    return 0;
}

by 像素旋转 @ 2021-01-31 14:32:06

@ExplodingKonjac 感谢大佬!! 我去消化消化


by Meatherm @ 2021-01-31 14:33:12

盲猜一波楼主大学生 2333


by 像素旋转 @ 2021-01-31 14:34:11

@Meatherm 猜对了 编程起步太晚了(叹气)


by CGDGAD @ 2021-01-31 14:38:15

OI,信息学奥林匹克竞赛。

主要面向中学生的。但也有很多小学大佬很强。 例如 @ expwmh 。


by CGDGAD @ 2021-01-31 14:39:20

u1s1这题搞个class,还弄什么指针真的没必要


by 像素旋转 @ 2021-01-31 14:40:43

@NSObject 谢谢大佬科普 进了洛谷后 我清楚的知道现在的小学生编程能力有多强了


by JohnFKennedy @ 2021-01-31 15:09:06

抄书它不香吗


by 像素旋转 @ 2021-02-01 08:37:50

@someone 没买深基(笑哭) 话说深基好用吗


by JohnFKennedy @ 2021-02-01 18:13:24

@像素旋转 不好用!上次抄约瑟夫问题4个WA


by 像素旋转 @ 2021-02-02 09:53:38

@someone 哈哈哈幸亏没买


上一页 | 下一页