[Codeforces493A] Vasya and Football

描述 Description

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.

输入格式 InputFormat

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.

输出格式 OutputFormat

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).

样例输入 SampleInput

MC
CSKA
9
28 a 3 y
62 h 25 y
66 h 42 y
70 h 25 y
77 a 4 y
79 a 25 y
82 h 42 r
89 h 16 y
90 a 13 r

样例输出 SampleOutput

MC 25 70
MC 42 82
CSKA 13 90


Codeforces 493A


代码 Code

作为 Div2 的 A 这题略麻烦吧。。。

#include <stdio.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
int i,j,t,n,m,l,r,k,z,y,x;
char ta[100],tb[100],c[2],ch[2];
int a[100],b[100];
bool ua[100],ub[100];
struct data
{
    char c[2],ch[2];
    int x,y;
    bool operator <(const data& temp) const
    {
        return x<temp.x;
    }
}d[100];
int main()
{
    scanf("%s",ta);
    scanf("%s",tb);
    scanf("%d",&n);
    for (i=1;i<=n;i++)
    {
        scanf("%d%s%d%s",&d[i].x,d[i].c,&d[i].y,d[i].ch);
    }
    sort(d+1,d+n+1);
    for (i=1;i<=n;i++)
    {
        if (d[i].c[0]=='a')
        {
            b[d[i].y]+=(d[i].ch[0]=='y')?1:2;
            if (b[d[i].y]>=2 && !ub[d[i].y])
            {
                printf("%s %d %d\n",tb,d[i].y,d[i].x);
                ub[d[i].y]=true;
            }
        }
        else
        {
            a[d[i].y]+=(d[i].ch[0]=='y')?1:2;
            if (a[d[i].y]>=2 && !ua[d[i].y])
            {
                printf("%s %d %d\n",ta,d[i].y,d[i].x);
                ua[d[i].y]=true;
            }
        }
    }
    return 0;
}