uva 127
开始用的是vector<sta
#include<iostream> #include<cstring> #include<vector> #include<stack> using namespace std; struct card { char ch[2]; }; bool is_match(card a,card b) { if(a.ch[0]==b.ch[0]||a.ch[1]==b.ch[1])return 1; return 0; } int main() { card ca; vector<stack<card> > piles; while(cin>>ca.ch&&strcmp(ca.ch,"#")) { stack<card> s; s.push(ca); piles.push_back(s); if(piles.size()==52) { while(true) { int i; for(i=0;i!=piles.size();i++) { if(i>=3&&is_match(piles[i].top(),piles[i-3].top())) { piles[i-3].push(piles[i].top()); piles[i].pop(); break; } if(i>=1&&is_match(piles[i].top(),piles[i-1].top())) { piles[i-1].push(piles[i].top()); piles[i].pop(); break; } } if(i==piles.size())break; else if(piles[i].empty()) { piles.erase(piles.begin()+i); } } cout<<piles.size()<<(piles.size()==1?" pile remaining:":" piles remaining:"); for(int i=0;i!=piles.size();i++)cout<<' '<<piles[i].size(); cout<<endl; piles.clear(); } } return 0; }
ck<string> >;然后就是超时,后来看人家的,改成char ch[2];struct card{char ch[2];};vector<stack<card> >.