POJ 1214 解题报告
来源:互联网 发布:淘宝账号申诉入口 编辑:程序博客网 时间:2024/05/03 21:57
#include <iostream>#include <string>#include <stack>using namespace std;const int maxn=53;int mount;stack<string> s[maxn];void stackInput();void moveCard();void finalOutput();bool isMatch(string s1,string s2);int main(){string str;while(cin >> str,str!="#"){s[0].push(str);stackInput();moveCard();finalOutput();}return 0;}void stackInput(){mount=52;string str;for(int i=1;i<mount;i++){cin >> str;s[i].push(str);//把输入的数据压入栈中}}void moveCard()//模拟纸牌的移动{int i;while(1){for(i=0;i<mount;i++){if(i>2&&isMatch(s[i].top(),s[i-3].top())){s[i-3].push(s[i].top());s[i].pop();break;}if(i>0&&isMatch(s[i].top(),s[i-1].top())){s[i-1].push(s[i].top());s[i].pop();break;}}if(i==mount) break;//栈数组已遍历完if(s[i].empty()){int k;for( k=i;k<mount-1;k++){s[k]=s[k+1];//栈也可以直接复制}while(!s[k].empty()) s[k].pop();//此部很关键,清空不需要的栈以免对下一组数据造成影响mount--;}}}bool isMatch(string s1,string s2){if(s1[0]==s2[0]||s1[1]==s2[1]) return true;else return false;}void finalOutput(){cout << mount << " piles remaining:";for(int j=0;j<mount;j++){cout << " " << s[j].size();while(!s[j].empty()) s[j].pop();//此步很关键,把栈清空以免对下组数据造成影响}cout << endl;}
这道题所用知识就是栈和模拟,用了很长时间才把题读懂,题目不是很难,但对于我这个菜鸟来说,用了很长的时间
- POJ 1214 解题报告
- poj数百篇解题报告
- poj 1141解题报告
- poj 1001解题报告
- poj 1011 解题报告
- poj 1087 解题报告
- poj 2153解题报告
- poj 2051解题报告
- POJ 1167 解题报告
- poj 1026 解题报告
- POJ 1077 解题报告
- POJ 1042 解题报告
- POJ 1095 解题报告
- POJ 1159解题报告
- poj 2312解题报告
- POJ 1001解题报告
- POJ 1002解题报告
- POJ 1006解题报告
- 笔记本知识文集-屏幕知识
- andriod目录
- POJ 1562
- 精典FormsAuthenticationTicket 分析
- javascript变量使用
- POJ 1214 解题报告
- 详解平板电脑和笔记本的区别
- 继承类的存储结构深层次理解
- WPS 操作之在指定页插入页码
- 数据库约束和连接的种类
- 激活脑细胞--两人猜数问题
- 一个人,向南走了一公里,然后向东走1公里,然后向北走一公里
- char与TCHAR相互转化
- C语言学习之关键字