zoukankan      html  css  js  c++  java
  • Card Game for Three

    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;
    }
    
  • 相关阅读:
    Qt自定义控件
    Qt布局的简单介绍
    Qt-ui的简单使用,常用控件(2)
    Qt--ui的简单使用(1)
    走向微信api开发
    一文一项目, 代码分析篇
    关于重写一些曾经写的东西
    最近发现一个数据库,好像可以用,于是做了一个调查,把一般常用的和可能踩的坑都查了一下方法,记录了一下,以后可以使用.
    号外一下
    抄来的,占个位儿【百度架构师是怎样搭建MySQL分布式集群】
  • 原文地址:https://www.cnblogs.com/xcfxcf/p/12301591.html
Copyright © 2011-2022 走看看