Input
The input contains multiple groups of data. The first row of each group of data contains an integer N (1 ≤ n ≤ 18), which indicates the total number of penalty points received by both parties. n = 0 indicates that the input is over. Then there are n rows. Each row is a string in the following format:
XXXX good: Indicates the penalty.
OrXXXX no good: Indicates that the penalty is not received.
WhereXXXXIndicates the player name (all composed of letters and spaces, so that no ambiguity exists)
Each line must not exceed 100 characters.
XXXXAndgoodAndXXXXAndno,noAndgoodThere must be only one space between them.
good,no goodAll are in lower case. This question is case-sensitive.
The data does not guarantee the final results of the penalty fight, nor does it guarantee that this set of data will be ended immediately after the final event (that is, you don't have to judge whether the penalty fight is over, just add the final penalty to the score ).
Output
Output a score board for each group of data. If a penalty is triggered, it is marked in the corresponding place.O, Marked if not enteredX. The information of the first penalty team is above, and the last penalty is below. The rightmost mark is the score of the two teams. For specific formats, see the sample output. NOTE: If only one penalty is received for one round, write the corresponding part of the penalty later.-.
Solution
The solution to this question is very simple. We need to consider two more factors.
(1) If the last two digits of a person are no, for example, abcno good
(2) If no good is included in a person's name, for example, ABC no good, it should be a penalty.
Therefore, the solution is to determine whether the input length is greater than 8. If the input length is smaller than 8, it must be entered. If the input length is greater than 8, The substrings with the last eight characters of the string are compared with "no good, if the number is equal, the penalty is not taken. Otherwise, the penalty is taken.
The Code is as follows:
#include <iostream>#include <string>using namespace std;int main(){ int testCases, lines, firstTeamGoal, secondTeamGoal; string goalInfo, firstTeam, secondTeam; cin >> testCases; while (testCases != 0){ lines = 0; firstTeam = secondTeam = ""; firstTeamGoal = secondTeamGoal = 0; getline(cin, goalInfo); while (lines < testCases){ getline(cin, goalInfo); int len = goalInfo.size(); if (len >= 8){ if (goalInfo.substr(len - 8, 8) == " no good"){ if (lines % 2 == 0) firstTeam += "X "; else secondTeam += "X "; } else{ if (lines % 2 == 0){ firstTeamGoal++; firstTeam += "O "; } else{ secondTeamGoal++; secondTeam += "O "; } } } else{ if (lines % 2 == 0){ firstTeamGoal++; firstTeam += "O "; } else{ secondTeamGoal++; secondTeam += "O "; } } lines++; } if (testCases % 2 == 1) secondTeam += "- "; for (int i = 0, len = (testCases + 1) / 2; i < len; i++) cout << i+1 << " "; cout << "Score" << endl << firstTeam << firstTeamGoal << endl << secondTeam <<secondTeamGoal<< endl; cin >> testCases; }}