UVa127,"Accordian" Patience
注意1堆的时候,pile后面没有s!!!!因为这个WA了一次,否则就1A了
犯了一个很幼稚很幼稚的错误,申请ans[]后玩了吧ans置0,结果调了好长好长时间,本来是敲完就能过的T T啊啊啊啊啊啊,一个多小时没了啊
附上我调试时写的代码(把每一次运转都输出了= =一个一个看的,真心用了好长时间,头都大了)
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#define maxn 100
using namespace std;
struct Node
{
int suit,rank;
//friend ostream& operator<<(ostream& cout,const Point& Node);
};
stack<Node> s[];
int init()
{
for (int i=;i<;i++) while (!s[i].empty()) s[i].pop();
char ch1,ch2;
cin>>ch1;
if (ch1=='#') return ;
cin>>ch2;
Node u;
if (isalpha(ch1))
switch (ch1){
case 'A':u.rank=;break;
case 'T':u.rank=;break;
case 'J':u.rank=;break;
case 'Q':u.rank=;break;
case 'K':u.rank=;break;
}
else u.rank=ch1-'';
switch (ch2){
case 'C':u.suit=;break;
case 'D':u.suit=;break;
case 'H':u.suit=;break;
case 'S':u.suit=;break;
}
s[].push(u);
for (int i=;i<=;i++){
cin>>ch1>>ch2;
if (isalpha(ch1))
switch (ch1){
case 'A':u.rank=;break;
case 'T':u.rank=;break;
case 'J':u.rank=;break;
case 'Q':u.rank=;break;
case 'K':u.rank=;break;
}
else u.rank=ch1-'';
switch (ch2){
case 'C':u.suit=;break;
case 'D':u.suit=;break;
case 'H':u.suit=;break;
case 'S':u.suit=;break;
}
s[i].push(u);
}
}
int match(Node a,Node b){
if (a.suit==b.suit||a.rank==b.rank) return ;
return ;
}
ostream& operator<<(ostream& cout,const Node& p) {
cout<<p.rank<<(char)(p.suit+'B')<<" ";
}
int tot(){
int t=;
for (int i=;i<=;i++)
t+=s[i].size();
cout<<" "<<t;
}
int main()
{
while (init()){
int i=,k,j;
while(i<=){
if (s[i].empty()){
i++;
continue;
}
k=i,j=;
while (k>=&&j<) {k--;if(!s[k].empty()) j++;}
if(j==) if(match(s[k].top(),s[i].top())){
//cout<<s[i].top()<<"->"<<s[k].top();
s[k].push(s[i].top());
s[i].pop();
//cout<<" "<<s[k].top();
//tot();cout<<endl;
i=k;
continue;
}
k=i;j=;
while (k>=&&j<){k--;if(!s[k].empty()) j++;}
if(j==)if(match(s[k].top(),s[i].top())){
//cout<<s[i].top()<<"->"<<s[k].top();
s[k].push(s[i].top());
s[i].pop();
//cout<<" "<<s[k].top();
//tot();cout<<endl;
i=k;
continue;
}
i++;
}
int ans[],top=;
memset(ans,,sizeof(ans));
for (i=;i<=;i++)
if (s[i].size()!=){
top++;
ans[top]=s[i].size();
}
if (top==)cout<<top<<" pile remaining:";
else cout<<top<<" piles remaining:";
for (i=;i<=top;i++) cout<<" "<<ans[i];
cout<<endl;
}
}
UVa127,"Accordian" Patience的更多相关文章
- [刷题]算法竞赛入门经典(第2版) 6-9/UVa127 - "Accordian" Patience
题意:52张牌排一行,一旦出现任何一张牌与它左边的第一张或第三张"匹配",即花色或点数相同,则须立即将其移动到那张牌上面,将其覆盖.能执行以上移动的只有压在最上面的牌.直到最后没有 ...
- ACM学习历程——UVA127 "Accordian" Patience(栈, 链表)
Description ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patie ...
- UVA-127 "Accordian" Patience (模拟)
题目大意:一种纸牌游戏,将52张扑克牌排成一列,每次操作可将一张扑克牌移到它的前一张或前面第三张上当牌的点数或花色匹配时.每次都移动最靠左的扑克牌,并且能移动三格就移动三格.求最终扑克牌状态. 题目分 ...
- UVA-127 "Accordian" Patience(模拟)
题目: 把52张牌从左到右排好,每张牌自成一个牌堆.当某张牌与它左边那张牌或者左边第三张牌匹配时(花色或者点数相同)时,就把这张牌移到那张牌上面. 移动之后还要查看是否可以进行其他移动.只有位于牌堆顶 ...
- ACM学习历程——UVA 127 "Accordian" Patience(栈;模拟)
Description ``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patie ...
- Uva 127 poj 1214 `Accordian'' Patience 纸牌游戏 模拟
Input Input data to the program specifies the order in which cards are dealt from the pack. The inpu ...
- UVa 127 - "Accordian" Patience
题目:52张扑克,从左到右在平面上排列,按着如下规则处理: 1.按照从左到右的顺序,如果一张牌和左边的第一张或者第三张匹配,就把它放到对应的牌上面. 2.如果可以移动到多个位置,移动到最左端的牌上面. ...
- 【习题 6-9 UVA - 127】"Accordian" Patience
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 链表模拟即可. 1pile不能加s... [代码] #include <bits/stdc++.h> using nam ...
- ``Accordian'' Patience
``Accordian'' Patience You are to simulate the playing of games of ``Accordian'' patience, the rule ...
随机推荐
- Python笔记2.1
所有类型如下图: 一 基础数据类型 1)数字类型 复制代码 >>> 2/2+2*2 5.0 >>> (50-5*6)/4 5.0 >>> 8/5 ...
- 201521123114 《Java程序设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 Q1. 互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了使用syn ...
- 201521123118《java程序与设计》第11周学习总结
1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容 2. 书面作业 1. 互斥访问与同步访问 完成题集4-4(互斥访问)与4-5(同步访问) 1.1 除了使用synch ...
- 201521123020 《Java程序设计》第9周学习总结
1.本周学习总结 2. 书面作业 1.常用异常 题目5-1 1.1 截图你的提交结果(出现学号) 1.2 自己以前编写的代码中经常出现什么异常.需要捕获吗(为什么)?应如何避免? 答:数组越界:不需要 ...
- python日记_01 python实现6个人围成一圈,扔到第三个人出局,循环扔的问题。
#!/usr/bin/python shoplist=['mango','apple','carrot','banana','oracle','python'] length = len(shopli ...
- java使用POI操作XWPFDocument 生成Word实战(一)
注:我使用的word 2016功能简介:(1)使用jsoup解析html得到我用来生成word的文本(这个你们可以忽略)(2)生成word.设置页边距.设置页脚(页码),设置页码(文本) 一.解析ht ...
- Struts2第二篇【开发步骤、执行流程、struts.xml讲解、defalut-struts讲解】
前言 我们现在学习的是Struts2,其实Struts1和Struts2在技术上是没有很大的关联的.Struts2其实基于Web Work框架的,只不过它的推广没有Struts1好,因此就拿着Stru ...
- Python学习笔记005_文件_OS_模块_pickle
>>> >>> # 文件 open()方法是打开文件,它有很多参数,第一个文件名是必须的(带路径)>>> >>> f = ope ...
- c#中的格式输出
Reference:http://blog.csdn.net/fightfaith/article/details/48137235
- Spring MVC 的文件下载
在看Spring MVC文件下载之前请先看Spring MVC文件上传 地址:http://www.cnblogs.com/dj-blog/p/7535101.html 文件下载比较简单,在超链接中指 ...