注意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[53]; int init() { for (int i=0;i<53;i++) while (!s[i].empty()) s[i].pop(); char ch1,ch2; cin>>ch1; if (ch1=='#') return 0; cin>>ch2; Node u; if (isalpha(ch1)) switch (ch1){ case 'A':u.rank=1;break; case 'T':u.rank=10;break; case 'J':u.rank=11;break; case 'Q':u.rank=12;break; case 'K':u.rank=13;break; } else u.rank=ch1-'0'; switch (ch2){ case 'C':u.suit=1;break; case 'D':u.suit=2;break; case 'H':u.suit=3;break; case 'S':u.suit=4;break; } s[1].push(u); for (int i=2;i<=52;i++){ cin>>ch1>>ch2; if (isalpha(ch1)) switch (ch1){ case 'A':u.rank=1;break; case 'T':u.rank=10;break; case 'J':u.rank=11;break; case 'Q':u.rank=12;break; case 'K':u.rank=13;break; } else u.rank=ch1-'0'; switch (ch2){ case 'C':u.suit=1;break; case 'D':u.suit=2;break; case 'H':u.suit=3;break; case 'S':u.suit=4;break; } s[i].push(u); } } int match(Node a,Node b){ if (a.suit==b.suit||a.rank==b.rank) return 1; return 0; } ostream& operator<<(ostream& cout,const Node& p) { cout<<p.rank<<(char)(p.suit+'B')<<" "; } int tot(){ int t=0; for (int i=1;i<=52;i++) t+=s[i].size(); cout<<" "<<t; } int main() { while (init()){ int i=2,k,j; while(i<=52){ if (s[i].empty()){ i++; continue; } k=i,j=0; while (k>=1&&j<3) {k--;if(!s[k].empty()) j++;} if(j==3) 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=0; while (k>=1&&j<1){k--;if(!s[k].empty()) j++;} if(j==1)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[100],top=0; memset(ans,0,sizeof(ans)); for (i=1;i<=52;i++) if (s[i].size()!=0){ top++; ans[top]=s[i].size(); } if (top==1)cout<<top<<" pile remaining:"; else cout<<top<<" piles remaining:"; for (i=1;i<=top;i++) cout<<" "<<ans[i]; cout<<endl; } }