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. UML 学习地址

    UML 学习地址 网址:http://www.uml.org.cn/oobject/201609092.asp http://www.uml.org.cn/oobject/201009081.asp ...

  2. Visual Studio容器项目工程化心得

    引言 关注博主的网友会看到我使用ASP.NET Core 容器化部署企业级项目的过程, 回想到开发过程中,鄙人有一些工程化心得, 分享给同学们. 项目工程化 因为本项目涉及单元测试Project.容器 ...

  3. SQL中SUM函数和CASE WHEN联合使用

    SELECT SUM(case WHEN sex=1 then 1 else 0 end )as '男生', SUM(case when sex =2 then 1 else 0 end )'女生'F ...

  4. spring boot 启动报:Composite-id class must implement Serializable: xxx错误

    问题 在对spring boot项目进行修改后,重新启动时报如下错误: Composite-id class must implement Serializable: xxx xxx为具体的类 原因 ...

  5. spring配置与使用

    1. 创建基于java的配置. 配置极少量的XML来启用java配置: <?xml version="1.0" encoding="UTF-8"?> ...

  6. 洛谷U3348 A2-回文数

    U3348 A2-回文数 题目背景 方方方很喜欢回文数,于是就有了一道关于回文数的题目. 题目描述 求从小到大第n(1<=n<=10^18)个回文数. 注释:出题人认为回文数不包括0. 输 ...

  7. 《SQL 进阶教程》 case:在 UPDATE 语句里进行条件分支

    1.对当前工资为30万日元以上的员工,降薪10%:2.对当前工资为25万日元以上且不满28万日元的员工,加薪20% update salaries set salary = case when sal ...

  8. Swing 实现的Gui链表

    https://gitee.com/dgwcode/MyJavaCode -Freight类可以实现的功能·构造方法:初始空车厢有5个·装货:当运往某地点的货物大于等于4个的时候,如果有空车箱,则先占 ...

  9. Codeforces 1167E(思路、数据处理)

    思路 不难想到枚举\(l\),那如何高效求出最小的\(r\)?这样答案加上\(x-r+1\)即可. 如果\(l\)并没在序列里出现--没啥想法:如果\(l\)是序列里的数,我们可以做的事情是记下每个数 ...

  10. 常用的http网页错误代码表---------495引发的一个简单到爆,但基于国内环境只能呵呵呵的血案

    敲代码敲出了个网页错误代码 495. 然后,正常的跑去百度,看了一堆还是没有完整的网页错误代码,应该说国内的环境的网页错误代码表只有官方的那几个,那么只能FQ了. 去到谷歌,一查全是俄语,乐了,明白是 ...