请问各位大佬,第一个为什么会WA
查看原帖
请问各位大佬,第一个为什么会WA
921649
ArcWinz楼主2023/3/10 17:45
#include<iostream>
#include<cstring>
#include<sstream>
using namespace std;

class ID
{
	public:
		string message, name, Chinese, math, English;
		int pos1, pos2, pos3;
		int C, M, E, all;
		
		void Find()
		{
			pos1 = message.find(" ");
			pos2 = message.find(" ", pos1 + 1);
			pos3 = message.find(" ", pos2 + 1);
			
			name = message.substr(0, pos1);
			Chinese = message.substr(pos1 + 1, pos2 - pos1 - 1);
			math = message.substr(pos2 + 1, pos3 - pos2 - 1);
			English = message.substr(pos3 + 1, message.length() - pos3 - 1);
			
			istringstream ss(Chinese);
			ss >> C;
			istringstream ss1(math);
			ss1 >> M;
			istringstream ss2(English);
			ss2 >> E;
			
			all = C + M + E;
		}
};

int main()
{
	string Highest_Student;
	int max_all = -9999, max_C, max_M, max_E;
	
	freopen("P5740_1.in","r",stdin);  
	freopen("P5740_1.out","w",stdout);
	
	int N;
	cin >> N;
	
	cin.ignore(); 
	
	string input;
	
	ID student[N];
	
	for (int i = 0; i < N; i++)
	{
		getline(cin, student[i].message);
		student[i].Find();
		
		if (student[i].all > max_all)
		{
			Highest_Student = student[i].name;
			max_C = student[i].C;
			max_M = student[i].M;
			max_E = student[i].E;
			
			max_all = student[i].all;
		}
	} 
	
	cout << Highest_Student << " " << max_C << " " << max_M << " " << max_E;
	
	fclose(stdin);
	fclose(stdout);
	
	return 0; 
}
2023/3/10 17:45
加载中...