본문 바로가기

코드포스

[코드포스 Practice4] D. Vasya and Football

Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red card.

Vasya is watching a recorded football match now and makes notes of all the fouls that he would give a card for. Help Vasya determine all the moments in time when players would be given red cards if Vasya were the judge. For each player, Vasya wants to know only the first moment of time when he would receive a red card from Vasya.

 

Input

The first line contains the name of the team playing at home. The second line contains the name of the team playing away. Both lines are not empty. The lengths of both lines do not exceed 20. Each line contains only of large English letters. The names of the teams are distinct.

Next follows number n (1 ≤ n ≤ 90) — the number of fouls.

Each of the following n lines contains information about a foul in the following form:

  • first goes number t (1 ≤ t ≤ 90) — the minute when the foul occurs;
  • then goes letter "h" or letter "a" — if the letter is "h", then the card was given to a home team player, otherwise the card was given to an away team player;
  • then goes the player's number m (1 ≤ m ≤ 99);
  • then goes letter "y" or letter "r" — if the letter is "y", that means that the yellow card was given, otherwise the red card was given.

The players from different teams can have the same number. The players within one team have distinct numbers. The fouls go chronologically, no two fouls happened at the same minute.

 

Output

For each event when a player received his first red card in a chronological order print a string containing the following information:

  • The name of the team to which the player belongs;
  • the player's number in his team;
  • the minute when he received the card.

If no player received a card, then you do not need to print anything.

It is possible case that the program will not print anything to the output (if there were no red cards).

 


이 문제는 지문이 길어서 오래 걸렸다. 그래도 좀 요령이 생겨서 먼저 예시를 적어놓고 읽었음. 입출력 같은 경우는 예시에 적어가면서 읽으면 좀 더 잘 이해가 된다. 

 

해석하는데 오래 걸렸지만 문제는 쉬웠다. 레드카드를 받는 순간을 기록하는 거라 옐로카드를 받을 때 이미 벌점이 1개이거나, 레드카드를 받을 때 벌점이 0개이거나 1개일 때 기록하면 된다. 나머지 경우는 이미 레드카드를 받거나 레드카드를 받기엔 foul이 적다. 

 

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
 
using i64 = long long;
 
int main() {
    string h, a;
    int n;
    vector<int> hs(100, 0);
    vector<int> as(100, 0); 
    
    cin >> h >> a >> n;
    
    for(int i = 0; i < n; i++){
        int time, player;
        char team, card;
        scanf("%d %c %d %c", &time, &team, &player, &card);
        
        if(team == 'a'){
            if(card == 'y'){
                if(as[player] == 1)
                    cout << a << " " << player << " " << time << endl;  
                as[player]++;
            }
            else {
                if(as[player] == 1 || as[player] == 0)
                    cout << a << " " << player << " " << time << endl;  
                as[player] += 2;
            }
        }
        else {
            if(card == 'y'){
                if(hs[player] == 1)
                    cout << h << " " << player << " " << time << endl;  
                hs[player]++;
            }
            else {
                if(hs[player] == 1 || hs[player] == 0)
                    cout << h << " " << player << " " << time << endl;  
                hs[player] += 2;
            }
        }
    }
    
    
    return 0;
}

코드로 그대로 옮겨놨다. 입력받고 배열에 넣어서 확인해서 맞으면 출력.