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 a, b 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 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.

Constraints

1≦|SA|≦100

1≦|SB|≦100

1≦|SC|≦100

Each letter in SA, SB, SC is 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:

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.

#include <bits/stdc++.h>
using namespace std;
string a,b,c;
int sa,sb,sc;
int bn;
int la = -1,lb = -1,lc = -1;
int main(){
//freopen("in","r",stdin);
cin >> a >> b >> c; sa = a.size();
sb = b.size();
sc = c.size();
bn = 1;
while(1) {
if(la == sa){
puts("A");
break;
}else if(lb == sb){
puts("B");
break;
}else if(lc == sc){
puts("C");
break;
}
if (bn == 1) {
la++;
bn = a[la] - 'a' + 1;
} else if (bn == 2) {
lb++;
bn = b[lb] - 'a' + 1;
} else if (bn == 3) {
lc++;
bn = c[lc] - 'a' + 1;
} }
return 0;
}

Card Game for Three的更多相关文章

  1. Lesson 3 Please send me a card

    Text Postcards always spoil my holidays. Last summer, I went to Italy. I visited museums and sat in ...

  2. iOS - Card Identification 银行卡号识别

    1.CardIO 识别 框架 GitHub 下载地址 配置 1.把框架整个拉进自己的工程,然后在 TARGETS => Build Phases => Link Binary With L ...

  3. HDOJ 4336 Card Collector

    容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  4. Opensuse enable sound and mic card

    Install application pavucontrol Run pavucontrol You will see the configuration about sound card and ...

  5. 进监狱全攻略之 Mifare1 Card 破解

    补充新闻:程序员黑餐馆系统 给自己饭卡里充钱 ,技术是双刃剑,小心,小心! 前言 从M1卡的验证漏洞被发现到现今,破解设备层出不穷,所以快速傻瓜式一键破解不是本文的重点,年轻司机将从本文中获得如下技能 ...

  6. Card(bestcoder #26 B)

    Card Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  7. [OpenJudge 3061]Flip The Card

    [OpenJudge 3061]Flip The Card 试题描述 There are N× Ncards, which form an N× Nmatrix. The cards can be p ...

  8. [杂谈]交通工具orca card

    How and Where to Use the ORCA Card The Microsoft ORCA card provides unlimited rides on all buses, tr ...

  9. [OrangePi] Backup internal EMMC to SD Card

    Boot your Orange PI board from EMMC without SD Card inserted login insert your SD Card Run: sudo ins ...

  10. [OrangePi] Installation on SD Card

    Download any of the available images (xz archive) from Mega or GoogleDrive Download scriptbin_kernel ...

随机推荐

  1. Coloring Colorfully

    问题 C: Coloring Colorfully 时间限制: 1 Sec  内存限制: 128 MB[提交] [状态] 题目描述 N块瓦片从左到右排成一行.每个块的初始颜色由长度为N的字符串S表示. ...

  2. Linux - cron - cron 表达式

    概述 之前 cron 的补充 这次介绍下 表达式 背景 之前有说过 cron 这次说下 表达式 1. 准备 环境 os centos7 2. 模板文件 文件 位置 /etc/crontab 作用 系统 ...

  3. zabbix_agentd无法启动,cannot open log 错误

    最近有一台服务器的zabbix启动异常,看日志有如下报错 zabbix_agentd []: cannot open log: cannot create semaphore ] No space l ...

  4. 发送数据给sap和接收

    1.确保已经连通sap 2.发送数据:这是以表的形式发送,而且是批量发送给sap 3.接收sap返回信息:这个比较特别,碰到时试一试 package com.yiyezhiqiu.lyh.utils; ...

  5. MySQL移动数据库位置

    http://zlyang.blog.51cto.com/1196234/1726029 需求:MySQL数据库文件原位置:/var/lib/mysql 要移动至:/data/mysql 1.首先在/ ...

  6. php抛出异常Exception和\Exception使用区别

    没有定义命名空间的情况下 , Exception和\Exception 均可正常执行抛出异常;定义命名空间的情况 , Exception 会在定义的命名空间下找对应的异常类 , 如果没有定义异常类 , ...

  7. 【转载】Java容器的线程安全

    转自:http://blog.csdn.net/huilangeliuxin/article/details/12615507 同步容器类 同步容器类包括Vector和Hashtable(二者是早期J ...

  8. vs2017运行网站,代码停止,浏览器页面关闭问题解决

    问题描述: 在项目开发过程中,如果程序出现了异常,我们一般都会暴露在浏览器中,但是最近我使用vs2017,发现项目一旦停止,浏览器也自动关闭了,没法查看具体错误详情(当然除了单步调试什么的),很是不爽 ...

  9. Maven快速创建SpringMVC web(1)

     Maven快速创建SpringMVC web工程详解  转自:http://blog.csdn.net/cndmss/article/details/52184836

  10. [爬坑日记] 安卓模拟器1903蓝屏 没开hyper-v

    先说解决方案: 我在升级完1903之后短短几个小时蓝屏了两次 还是不同原因,不由得开始怀疑这个版本的稳定性,随后发现只有启动安卓模拟器的时候必然蓝屏(还有一次蓝屏实在安装驱动的时候) 经过百度得知需要 ...