127
/* 水题 体现出题目看不懂 额 */ #include <iostream> #include <string.h> #include <cstdio> #include <vector> using namespace std; const int maxn=55; struct card{ char A,B; card(char a=0,char b=0){ A=a;B=b; } bool operator == (const card F){ if(A==F.A||B==F.B) return true; else return false; } }; struct stac{ card T[maxn]; int t; void sclear(){ t=0;} bool sempty(){ return t==0;} card top(){ return T[t]; } void push(card R){ T[++t]=R;} void pop(){t--;} int ssize(){ return t;} }; int main() { card temp,t1,tt,t3; stac T,TT,T1,T3; while(1){ bool flag=0; vector<stac>Q; char str[5]; for(int i=0;i<52;i++){ scanf("%s",str); if(str[0]=='#') { flag=1;break; } temp=card(str[0],str[1]); T.sclear(); T.push(temp); Q.push_back(T); } if(flag) break; while(1){ flag=1; int a,b; for(int i=1;i<Q.size();i++){ tt=Q[i].top(); if(i-3>=0) { t3=Q[i-3].top(); if(tt==t3) { flag=0; a=i;b=i-3; break; } } if(i-1>=0) { t1=Q[i-1].top(); if(tt==t1) { flag=0;a=i;b=i-1; break; } } } if(flag) break; Q[b].push(tt); Q[a].pop(); if(Q[a].sempty()){ Q.erase(Q.begin()+a);} } int a=Q.size(); if(a==1){ printf("1 pile remaining: %d",Q[0].ssize());} else { printf("%d piles remaining:",a); for(int i=0;i<Q.size();i++) printf(" %d",Q[i].ssize()); } printf("\n"); } return 0; }