这串代码本身非常垃圾,但是由于之前刚学了下怎么分割字符串,所以我这边也试了下,在本地运行是可以的。但是交上去就RE了 我感觉好奇怪,请教下大佬。
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int computeMoney(int final, int s_class, const string& isLeader, const string& isStudent, int paper) {
int money = 0;
if (final > 80 && paper >= 1) {
money += 8000;
}
if (final > 85 && s_class > 80) {
money += 4000;
}
if (final > 90) {
money += 2000;
}
if (final > 85 && isStudent == "Y") {
money += 1000;
}
if (s_class > 80 && isLeader == "Y") {
money += 850;
}
return money;
}
int main() {
int n;
cin >> n;
cin.ignore();
int sum = 0;
int maxMoney = 0;
string maxStudent = "";
while (n--) {
string str;
getline(cin, str);
size_t space1 = str.find(' ');
size_t space2 = str.find(' ', space1 + 1);
size_t space3 = str.find(' ', space2 + 1);
size_t space4 = str.find(' ', space3 + 1);
size_t space5 = str.find(' ', space4 + 1);
string name = str.substr(0, space1);
int final = stoi(str.substr(space1 + 1, space2 - space1 - 1));
int s_class = stoi(str.substr(space2 + 1, space3 - space2 - 1));
string isLeader = str.substr(space3 + 1, space4 - space3 - 1);
string isStudent = str.substr(space4 + 1, space5 - space4 - 1);
int paper = stoi(str.substr(space5 + 1));
int money = computeMoney(final, s_class, isLeader, isStudent, paper);
if (money > maxMoney) {
maxMoney = money;
maxStudent = name;
}
sum += money;
}
cout << maxStudent << endl;
cout << maxMoney << endl;
cout << sum << endl;
return 0;
}