Atcoder 045

B - 3人でカードゲームイージー / Card Game for Three (ABC Edit)


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Alice, Bob and Charlie are playing Card Game for Three, as below:

  • At first, each of the three players has a deck consisting of some number of cards. Each card has a letter ab or c written on it. The orders of the cards in the decks cannot be rearranged.
  • The players take turns. Alice goes first.
  • If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)
  • If the current player's deck is empty, the game ends and the current player wins the game.

You are given the initial decks of the players. More specifically, you are given three strings SASB and SC. The i-th (1≦i≦|SA|) letter in SA is the letter on the i-th card in Alice's initial deck. SB and SC describes Bob's and Charlie's initial decks in the same way.

Determine the winner of the game.

Constraints

  • 1≦|SA|≦100
  • 1≦|SB|≦100
  • 1≦|SC|≦100
  • Each letter in SASBSC is ab or c.

Input

The input is given from Standard Input in the following format:

SA
SB
SC

Output

If Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.


Sample Input 1

Copy
aca
accc
ca

Sample Output 1

Copy
A

The game will progress as below:

  • Alice discards the top card in her deck, a. Alice takes the next turn.
  • Alice discards the top card in her deck, c. Charlie takes the next turn.
  • Charlie discards the top card in his deck, c. Charlie takes the next turn.
  • Charlie discards the top card in his deck, a. Alice takes the next turn.
  • Alice discards the top card in her deck, a. Alice takes the next turn.
  • Alice's deck is empty. The game ends and Alice wins the game.

Sample Input 2

Copy
abcb
aacb
bccc

Sample Output 2

Copy
C

Submit

这个比赛题目很有意思,B题,A B C 三个人每人一个字符串,该字符串只包含 abc,A先从串首拿出一个字符,并删除该字符,如果删除的字符是 a,下一轮

还是A操作,如果是b,那么小一轮B操作,如果是c,下一轮C操作,同样其他人也按照这样的规则进行,最后谁的字符串先删完,谁赢,输出赢家  A ||  B || C

简单模拟一下就可以了

#include <iostream>
#include <string.h>
using namespace std;
char A[104],B[105],C[105];
int main()
{
    int a,b,c;
    int la,lb,lc;

    while(cin>>A>>B>>C)
    {
        int tmp;
        la=strlen(A);
        lb=strlen(B);
        lc=strlen(C);
        tmp=1;
        a=b=c=-1;
        while(1)
        {
            if(a==la)
            {
                cout<<"A"<<endl;
                break;
            }
            else if(b==lb)
            {
                cout<<"B"<<endl;
                break;
            }
            else if(c==lc)
            {
                cout<<"C"<<endl;
                break;
            }
            if(tmp==1)
            {
                  a++;
                tmp=A[a]-'a'+1;


            }
            else if(tmp==2)
            {
                 b++;
                tmp=B[b]-'a'+1;

            }
            else if(tmp==3)
            {
               c++;
                tmp=C[c]-'a'+1;

            }
        }
        //cout<<(a+b)*h/2<<endl;
    }
    return 0;
}

|


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值