Try Again

Codefroces 493A Vasya and Football

A. Vasya and Football
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Examples
Input
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
Output
MC 25 70
MC 42 82
CSKA 13 90
水题;
精简代码:
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
int n,t,num,k,vis[105][2];
char ch,s[2][30],col;
int main()
{
    scanf("%s%s",s[0],s[1]);
    scanf("%d",&n);
    memset(vis,0,sizeof(vis));
    for(int i=0;i<n;i++)
    {
        scanf("%d %c %d %c",&t,&ch,&num,&col);
        k=(ch=='a');
        if(col=='y')
        {
            if(!vis[num][k]) vis[num][k]++;
            else if(vis[num][k]==2) continue;
            else
            {
                vis[num][k]=2;
                cout<<s[k]<<' '<<num<<' '<<t<<endl;
            }
        }
        else
        {
            if(vis[num][k]!=2)
                cout<<s[k]<<' '<<num<<' '<<t<<endl;
            vis[num][k]=2;
        }
    }
    return 0;
}

再来个丑代码:

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
map<int,int>h,a;
string home,away;
int n,number,t;
char s[2],ss[2];
struct Node
{
    int time;
    int num;
    string team;
    friend bool operator<(const Node & a,const Node &b)
    {
        return a.time<b.time;
    }
}node[105];
int main()
{
    cin>>home>>away;
    scanf("%d",&n);
    int pos=0;
    for(int i=0;i<n;i++)
    {
        cin>>t>>s>>number>>ss;
        if(ss[0]=='r')
        {
            if(s[0]=='a')
            {
                if(a[number]>=2) continue;
                else
                {
                    a[number]=2;
                    node[pos].team=away;
                    node[pos].num=number;
                    node[pos++].time=t;
                }
            }
            if(s[0]=='h')
            {
                if(h[number]>=2) continue;
                else
                {
                    h[number]=2;
                    node[pos].team=home;
                    node[pos].num=number;
                    node[pos++].time=t;
                }
            }
        }
        else
        {
            if(s[0]=='a')
            {
                if(a[number]==0) a[number]++;
                else if(a[number]>=2) continue;
                else
                {
                    a[number]=2;
                    node[pos].team=away;
                    node[pos].num=number;
                    node[pos++].time=t;
                }
            }
            if(s[0]=='h')
            {
                if(h[number]==0) h[number]++;
                else if(h[number]>=2) continue;
                else
                {
                    h[number]=2;
                    node[pos].team=home;
                    node[pos].num=number;
                    node[pos++].time=t;
                }
            }
        }
    }
    sort(node,node+pos);
    for(int i=0;i<pos;i++)
    {
        cout<<node[i].team<<' '<<node[i].num<<' '<<node[i].time<<endl;
    }
    return 0;
}

 

posted @ 2017-07-23 10:02  十年换你一句好久不见  阅读(176)  评论(0)    收藏  举报