#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<list>
#include<vector>
#include<cctype>
#include <algorithm>
#define N 1024
using namespace std;
struct stack
{
char str[53][3];
int top;
bool empty()
{
if(top==0)
return 1;
return 0;
}
void push(char s[])
{
strcpy(str[top++],s);
}
void pop()
{
top--;
}
void clear()
{
top=0;
}
};
stack s[53];
int len;
void remove(int i)
{
i++;
for(; i<len; i++)
{
if(s[i].empty())
break;
s[i-1]=s[i];
// s[i].pop();//有的时候自己想的和自己写出来的真的不一样!!
// s[i].clear();//有的时候自己想的和自己写出来的真的不一样!!
//两者的区别啊!!1
}
}
bool ok(char a[],char b[])
{
if(a[0]==b[0]||a[1]==b[1])
return 1;
return 0;
}
int main()
{
// freopen("ex.in","r",stdin);
char str[3];
while(cin>>str&&str[0]!='#')
{
len=52;
for(int i=0; i<53; i++)s[i].clear();
s[0].push(str);
for(int i=1; i<len; i++)
{
cin>>str;
s[i].push(str);
}
int i;
for(i=0; i<len;)
{
if(i>=3&&ok(s[i].str[s[i].top-1],s[i-3].str[s[i-3].top-1]))
{
s[i-3].push(s[i].str[s[i].top-1]);
s[i].pop();
if(s[i].empty())
{
remove(i);
len--;
}
i-=3;
}
else if(i>=1&&ok(s[i].str[s[i].top-1],s[i-1].str[s[i-1].top-1]))
{
s[i-1].push(s[i].str[s[i].top-1]);
s[i].pop();
if(s[i].empty())
{
remove(i);
len--;
}
i-=1;
}
else
i++;
}
cout<<len;
if(len==1)
cout<<" pile remaining:";
else
cout<<" piles remaining:";
for(int i=0; i<len; i++)
cout<<" "<<s[i].top;
cout<<endl;
}
return 0;
}
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<cstring> #include<list> #include<vector> #include<cctype> #include <algorithm> #define N 1024 using namespace std; struct stack { char str[53][3]; int top; bool empty() { if(top==0) return 1; return 0; } void push(char s[]) { strcpy(str[top++],s); } void pop() { top--; } void clear() { top=0; } }; stack s[53]; int len; void remove(int i) { i++; for(; i<len; i++) { if(s[i].empty()) break; s[i-1]=s[i]; // s[i].pop();//有的时候自己想的和自己写出来的真的不一样!! // s[i].clear();//有的时候自己想的和自己写出来的真的不一样!! //两者的区别啊!!1 } } bool ok(char a[],char b[]) { if(a[0]==b[0]||a[1]==b[1]) return 1; return 0; } int main() { // freopen("ex.in","r",stdin); char str[3]; while(cin>>str&&str[0]!='#') { len=52; for(int i=0; i<53; i++)s[i].clear(); s[0].push(str); for(int i=1; i<len; i++) { cin>>str; s[i].push(str); } int i; for(i=0; i<len;) { if(i>=3&&ok(s[i].str[s[i].top-1],s[i-3].str[s[i-3].top-1])) { s[i-3].push(s[i].str[s[i].top-1]); s[i].pop(); if(s[i].empty()) { remove(i); len--; } i-=3; } else if(i>=1&&ok(s[i].str[s[i].top-1],s[i-1].str[s[i-1].top-1])) { s[i-1].push(s[i].str[s[i].top-1]); s[i].pop(); if(s[i].empty()) { remove(i); len--; } i-=1; } else i++; } cout<<len; if(len==1) cout<<" pile remaining:"; else cout<<" piles remaining:"; for(int i=0; i<len; i++) cout<<" "<<s[i].top; cout<<endl; } return 0; }