UVa10978 - Let's Play Magic!(扑克类的游戏)
来源:互联网 发布:r语言入门 知乎 编辑:程序博客网 时间:2024/06/05 16:22
You have seen a card magic trick named "Spelling Bee". The process goes as follows:
- The magician first arranges 13 cards in a circle, as shown in the figure below.
- Starting from the marked position, he counts the cards clockwisely, saying "A--C--E".
- He turns the card at the "E" position, and... it is an Ace!
- Next, he takes away the Ace and continues to count the cards, saying "T--W--O".
- He turns over the card at position "O"... it is a Two!!
- He continues to do this with the rest of the cards from Three to King. :-)
Now, how does the magician arrange the cards?
Input
Input consists of several test cases. Each case begins with an integer N (1 ≤ N ≤ 52), the number of cards to be used in the magic trick. The following N lines show the order of the turning-over of the cards and the words to be spelt. None of the words will have more than 20 characters. The format for each card is a string with two characters: first the value, and second the suit.
Input ends with a test case where N=0. This test case should not be processed.
Output
For each case, your program should output the initial arrangement of the cards.
Sample Input
13AS ACE2S TWO3S THREE4C FOUR5C FIVE6C SIX7D SEVEN8D EIGHT9D NINETH TENJH JACKQH QUEENKH KING0
Sample Output
QH 4C AS 8D KH 2S 7D 5C TH JH 3S 6C 9D
import java.io.FileInputStream;import java.io.BufferedReader;import java.io.InputStreamReader;import java.io.PrintWriter;import java.io.OutputStreamWriter;import java.io.StreamTokenizer;import java.util.Arrays;public class Main{public static final boolean DEBUG = false;public BufferedReader cin;public PrintWriter cout;public StreamTokenizer tokenizer;public int n;public Card[] cards;public boolean[] vis;static class Card{String name, spelt;}public void init(){try {if (DEBUG) {cin = new BufferedReader(new InputStreamReader(new FileInputStream("e:\\uva_in.txt")));} else {cin = new BufferedReader(new InputStreamReader(System.in));}tokenizer = new StreamTokenizer(cin);tokenizer.resetSyntax();tokenizer.wordChars('a', 'z');tokenizer.wordChars('A', 'Z');tokenizer.wordChars('0', '9');tokenizer.wordChars(128 + 32, 255);tokenizer.whitespaceChars(0, ' ');tokenizer.commentChar('/');tokenizer.quoteChar('"');tokenizer.quoteChar('\'');cout = new PrintWriter(new OutputStreamWriter(System.out));} catch (Exception e) {e.printStackTrace();}}public String next(){try {tokenizer.nextToken();if (tokenizer.ttype == StreamTokenizer.TT_EOF) return null;else if (tokenizer.ttype == StreamTokenizer.TT_NUMBER) {return String.valueOf((int)tokenizer.nval);} else return tokenizer.sval;} catch (Exception e) {e.printStackTrace();return null;}}public boolean input(){n = Integer.parseInt(next());if (n == 0) return false;cards = new Card[n];for (int i = 0; i < n; i++) {cards[i] = new Card();cards[i].name = next();cards[i].spelt = next();}return true;}public int nextPos(int cur){int i = cur;while (vis[i]) i = (i + 1) % n;return i;}public void solve(){String[] ans = new String[n];vis = new boolean[n];Arrays.fill(vis, false);int cur = 0;for (int i = 0; i < n; i++) {int len = cards[i].spelt.length();for (int j = 0; j < len; j++) {cur = nextPos(cur);cur = (cur + 1) % n;}int prev = (cur - 1 + n) % n;ans[prev] = cards[i].name;vis[prev] = true;}for (int i = 0; i < n; i++) {if (i != 0) cout.print(" ");cout.print(ans[i]);}cout.println();cout.flush();}public static void main(String[] args){Main solver = new Main();solver.init();while (solver.input()) {solver.solve();}}}
0 0
- UVa10978 - Let's Play Magic!(扑克类的游戏)
- (1.1.6)UVA 10978 Let's Play Magic!(直叙式模拟)
- Let’s Play Games!
- let‘s play game!
- 2204 let's play dota.
- Let's play a game
- Let's go to play
- ZOJ2507 Let's play a game,ZOJ3113 POJ3480 HDU1907 John,Anti-SG游戏
- codeforces 235B - Let's Play Osu!
- codefrces 235B Let's Play Osu!
- zoj2507 Let's play a game
- CF235 Let's Play Osu![dp+概率]
- Codeforces 235B. Let's Play Osu!
- Sicily 1905. Let’s play UNO
- Codeforces 235B Let's Play Osu!
- zoj 2507 Let's play a game
- 杭电 Let's go to play
- hdu--Let's go to play
- Oracle数据库备份数据缺失的问题
- 【HDU】4862 Jump 费用流
- perf usage
- yarn学习心得 yarn上的程序开发
- Custom Component, Unreal Engine里定制组件
- UVa10978 - Let's Play Magic!(扑克类的游戏)
- 例子使用
- 字符串String 池
- CSS透明opacity和IE各版本透明度滤镜filter的最准确用法
- uC/OS-II 学习笔记:任务创建步骤
- 第一天-Java语言简介,环境搭建等
- 学拳录 24中盘 (07.29更新)
- 编程之美,3.11程序改错, 二分扩展
- 逆序输出