栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1214 "Accordian" Patience

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1214 "Accordian" Patience

#include <iostream>#include <string.h>#include <stdio.h>#include <stack>using namespace std;const int MAXN = 53;stack<string> nCard[MAXN]; int nIndex;void funcInput();void procMove();void funcOutput();bool isMatch(string str1, string str2);int main(){string nStr;while (cin >> nStr, nStr != "#"){nCard[0].push(nStr);funcInput();procMove();funcOutput();}return 0;}void funcInput(){string nStr;for (nIndex = 1; nIndex != 52; ++nIndex){cin >> nStr;nCard[nIndex].push(nStr);}}void procMove(){while (1){int pos;for (pos = 0; pos != nIndex; ++pos){if (pos > 2 && isMatch(nCard[pos-3].top(), nCard[pos].top())){nCard[pos-3].push(nCard[pos].top());break;}if (pos > 0 && isMatch(nCard[pos-1].top(), nCard[pos].top())){nCard[pos-1].push(nCard[pos].top());break;}}if (pos == nIndex) break;nCard[pos].pop();if (nCard[pos].empty()){for (int i = pos; i != nIndex - 1; ++i){nCard[i] = nCard[i+1]; }while (!nCard[nIndex-1].empty()) nCard[nIndex-1].pop();--nIndex;}}}void funcOutput(){cout << nIndex << " piles remaining:";for (int i = 0; i != nIndex; ++i){cout << ' ' << nCard[i].size();while ( !nCard[i].empty() ) nCard[i].pop();}cout << endl;}bool isMatch(string str1, string str2){if (str1[0] == str2[0] || str1[1] == str2[1]) return true;return false;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/375544.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号