论RE
查看原帖
论RE
1041765
AKkkk_TIX楼主2024/8/8 12:59
#include <bits/stdc++.h>
using namespace std;
struct stu {
	string name;
	int chinese, math, english, total;
	friend istream & operator >> ( istream &in, stu &x ) {
		cin >> x.name >> x.chinese >> x.math >> x.english;
	}
	friend ostream & operator << ( ostream &out, stu &x ) {
		cout << x.name << " " << x.chinese << " " << x.math << " " << x.english << '\n';
	}
}a[1010];
int n, i, j;
int main() {
	cin >> n;
	for (i = 0; i < n; i++){
		cin >> a[i];
		a[i].total = a[i].chinese + a[i].math + a[i].english;
	}
	for(int i = n - 1;i > 0;i--) {
		bool b = true;
		for(int j = 0;j < i;j++) {
			if (a[j].total < a[j + 1].total){
				swap(a[j], a[j + 1]);
				b = false;
			}
		}
		if (b) break;
	}
	
	cout << a[0];
	return 0;
}

为什么开了O2后全RE?

2024/8/8 12:59
加载中...