Time limit : 2sec / Memory limit : 256MB
Score : 200 points
Alice, Bob and Charlie are playing Card Game for Three, as below:
a
, b
or c
written on it. The orders of the cards in the decks cannot be rearranged.a
, Alice takes the next turn.)You are given the initial decks of the players. More specifically, you are given three strings SA, SB 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.
a
, b
or c
.The input is given from Standard Input in the following format:
SA SB SC
If Alice will win, print A
. If Bob will win, print B
. If Charlie will win, print C
.
aca accc ca
A
The game will progress as below:
a
. Alice takes the next turn.c
. Charlie takes the next turn.c
. Charlie takes the next turn.a
. Alice takes the next turn.a
. Alice takes the next turn.abcb aacb bccc
C
这个比赛题目很有意思,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;
}