Input

Input data to the program specifies the order in which cards are dealt from the pack. The input contains pairs of lines, each line containing 26 cards separated by single space characters. The final line of the input file contains a # as its first character. Cards are represented as a two character code. The first character is the face-value (A=Ace, 2-9, T=10, J=Jack, Q=Queen, K=King) and the second character is the suit (C=Clubs, D=Diamonds, H=Hearts, S=Spades).

Output

One line of output must be produced for each pair of lines (that between them describe a pack of 52 cards) in the input. Each line of output shows the number of cards in each of the piles remaining after playing ``Accordian patience'' with the pack of cards as described by the corresponding pairs of input lines.

Sample Input

QD AD 8H 5S 3H 5H TC 4D JH KS 6H 8S JS AC AS 8D 2H QS TS 3S AH 4H TH TD 3C 6S
8C 7D 4C 4S 7S 9H 7C 5D 2S KD 2D QH JD 6D 9D JC 2C KH 3D QC 6C 9S KC 7H 9C 5C
AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AD 2D 3D 4D 5D 6D 7D 8D TD 9D JD QD KD
AH 2H 3H 4H 5H 6H 7H 8H 9H KH 6S QH TH AS 2S 3S 4S 5S JH 7S 8S 9S TS JS QS KS
#

Sample Output

6 piles remaining: 40 8 1 1 1 1
1 pile remaining: 52 麻烦的模拟。手写栈,每个pile都是个栈,用pos数组来记录位置和pile编号的关系。
#include<cstdio>

struct card
{
char R, s;//Rank,suit
card(){}
card(char R, char s):R(R),s(s){}
bool operator == (const card& rhs) const {// match
return R == rhs.R || s == rhs.s;
}
}; struct Stack
{
card ele[];
int Top; card* top(){ return ele+Top;}
void pop(){Top--;}
void push(const card& x){
ele[++Top] = x;
}
}pile[]; int pileSz; int pos[];//pos 2 pile void Move(int p, int d)
{
int id = pos[p], pid = pos[p-d]; pile[pid].push(*pile[id].top());
pile[id].pop(); if(pile[id].Top == ){
pileSz--;
for(int i = p; i < pileSz; i++)
pos[i] = pos[i+];
}
} bool check()
{
int move3 = -;
for(int i = ;i < pileSz; i++) {
if( *pile[pos[i]].top() == *pile[pos[i-]].top()) { move3 = i; break; }
}
int move1 = -;
for(int i = ;i < pileSz; i++) {
if( *pile[pos[i]].top() == *pile[pos[i-]].top()) { move1 = i; break; }
} if(!~move1 && !~move3) return false; if(~move1&&~move3){
if(move1 < move3) Move(move1,);
else Move(move3,);
}
else {
if(~move1) Move(move1,);
else Move(move3,);
} return true;
} bool read(){
char buf[];
scanf("%s",buf);
if(*buf == '#') return false;
for(int i = ; i < ; i++) pos[i] = i;
pileSz = ;
for(int i = ; i < ; i++) pile[i].Top = ; pile[].push(card(*buf,buf[])); for(int i = ; i < ; i++) {
scanf("%s",buf);
pile[i].push(card(*buf,buf[]));
} return true;
} int main()
{
// freopen("in.txt","r",stdin);
while(read()){
while(check());
/* poj
printf("%d piles remaining:",pileSz);
for(int i = 0; i < pileSz; i++)
printf(" %d",pile[pos[i]].Top);
*/
if(pileSz>){
printf("%d piles remaining:",pileSz);
for(int i = ; i < pileSz; i++)
printf(" %d",pile[pos[i]].Top);
}
else printf("1 pile remaining: 52"); puts("");
}
return ;
}
 

Uva 127 poj 1214 `Accordian'' Patience 纸牌游戏 模拟的更多相关文章

  1. ACM学习历程——UVA 127 "Accordian" Patience(栈;模拟)

    Description  ``Accordian'' Patience  You are to simulate the playing of games of ``Accordian'' patie ...

  2. UVa 127 - &quot;Accordian&quot; Patience POJ 1214 链表题解

    UVa和POJ都有这道题. 不同的是UVa要求区分单复数,而POJ不要求. 使用STL做会比較简单,这里纯粹使用指针做了,很麻烦的指针操作,一不小心就错. 调试起来还是很费力的 本题理解起来也是挺费力 ...

  3. [刷题]算法竞赛入门经典(第2版) 6-9/UVa127 - "Accordian" Patience

    题意:52张牌排一行,一旦出现任何一张牌与它左边的第一张或第三张"匹配",即花色或点数相同,则须立即将其移动到那张牌上面,将其覆盖.能执行以上移动的只有压在最上面的牌.直到最后没有 ...

  4. HDU 2209 翻纸牌游戏 状态BFS

    翻纸牌游戏 Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem De ...

  5. hdu2209翻纸牌游戏

    翻纸牌游戏 Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Subm ...

  6. 翻纸牌游戏(dfs回溯)

    翻纸牌游戏 Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submiss ...

  7. HDU 2209 翻纸牌游戏(DFS)

    题目链接 Problem Description 有一种纸牌游戏,很有意思,给你N张纸牌,一字排开,纸牌有正反两面,开始的纸牌可能是一种乱的状态(有些朝正,有些朝反),现在你需要整理这些纸牌.但是麻烦 ...

  8. HDU 2209 翻纸牌游戏

    翻纸牌游戏 Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submiss ...

  9. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

随机推荐

  1. 7.19实习培训日志- java进阶

    java进阶 java集合 Collection List ArrayList jdk1.2,异步处理,性能高,线程不安全 Vector jdk1.0,同步处理,性能低,线程安全 Set HashSe ...

  2. CentOS6下用yum升级系统内核版本至最新

    首先当你决定升级内核时,要想清楚为什么升级内核,因为升级内核会带来很多麻烦.所以这种事情能避免就避免 导入 Public Key rpm --import https://www.elrepo.org ...

  3. CentOS6下用yum升级系统最新内核版本

    首先当你决定升级内核时,要想清楚为什么升级内核,因为升级内核会带来很多麻烦.所以这种事情能避免就避免 导入 Public Key rpm --import https://www.elrepo.org ...

  4. 51nod1107(逆序对数&归并排序)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1107 题意:中文题诶- 思路:通过题意可以发现对于两点p1(x ...

  5. CentOS6.5安装sqlite3[转]

    1.下载安装包:https://www.sqlite.org/download.html 2.解压 [root@mycentos ~]# tar xzvf sqlite-snapshot-201809 ...

  6. sesstionStorage和localStorage

    使用: 对于多页面的pc端,为了同步多页面的消息提醒,可以将数据储存在localStorage中,多页面共享同一个localStorage.然后使用setInterval轮询获取数据,执行逻辑代码 s ...

  7. redis 拒绝远程访问解决

    启动时报的警告: 1.Warning: no config file specified, using the default config. In order to specify a config ...

  8. 转 dos 下的 find 和 重定向 and 删除

    1.find /i "ora-" *.* > check.log del /Q .\log\*.* 附录: 我对findstr是如此的依赖,以至于当我向各位讲解find命令的 ...

  9. python 7 dict和set

    dict Python内置了字典:dict的支持,dict全称dictionary,在其他语言中也称为map,使用键-值(key-value)存储,具有极快的查找速度. 举个例子,假设要根据同学的名字 ...

  10. SSRS-lookupSet-DataSet-分组查询

    SSRS-lookupSet-DataSet-分组查询 来源:http://www.cnblogs.com/biwork/p/3621885.html 目录:http://www.cnblogs.co ...