Description
A common pastime for poker players at a poker table is to
shuffle stacks of chips. Shuffling chips is performed by starting
with two stacks of poker
chips,
The actual shuffle operation is performed by interleaving a chip
from

The single resultant
stack,
After the shuffle
operation,
For this problem, you will write a program to determine if a
particular resultant
stack
Input
The first line of input contains a single
integer
Each dataset consists of four lines of input. The first line of
a dataset specifies an integer
Output
Output for each dataset consists of a single line that
displays the dataset number (1
though
Sample Input
2
4
AHAH
HAHA
HHAAAAHH
3
CDE
CDE
EEDDCC
Sample Output
1 2
2 -1
#include iostream
#include string
#include map
using namespace std;
int main()
{
char s1[105], s2[105], s12[210], s[210];
int t, c, cou, x = 0, i, j, k;
cin>>t;
while(t--)
{
x++;
cou = 0;
cin>>c;
cin>>s1;
cin>>s2;
cin>>s12;
memset(s, '1', sizeof(s));
map < string, int>vis; //用map记录字符串出现与否。
vis[s12] = 1;
vis[s] = 0;
while(strcmp(s, s12) != 0 && vis[s] == 0) //出口两个:1.与目标相同了 2.又到了出现过的字符串,即进入”环“状态,此时必定不能洗到目标状态
{
vis[s] = 1;
for(i = j = k = 0 ; i < 2*c ; i++)
{
if(i%2 == 0)
{
s[i] = s2[j];
j++;
}
else
{
s[i] = s1[k];
k++;
}
}
s[i] = '\0';
cou++;
for(i = 0 ; i < c ; i++)
s1[i] = s[i];
for(j = c,k = 0 ; j < 2*c ; j++, k++)
s2[k] = s[j];
}
if(strcmp(s, s12) == 0)
cout<<x<<' '<<cou<<endl;
else
cout<<x<<' '<<"-1"<<endl;
}
return 0;
}