模拟/poj 3087 Shuffle'm Up

 1 #include<cstdio>
 2 #include<cstring>
 3 using namespace std;
 4 char s1[110],s2[110],ss[220];
 5 int len,n;
 6 
 7 int f()
 8 {
 9     int ans=0;
10     char t1[110],t2[110],tt[220];
11     strcpy(t1,s1);strcpy(t2,s2);
12     while (1)
13     {
14         ans++;
15         for (int i=0;i<len;i++)
16         {
17             tt[i*2]=t2[i];
18             tt[i*2+1]=t1[i];
19         }
20         tt[2*len]='\0';
21         if (strcmp(tt,ss)==0) return ans;
22         for (int i=0;i<len;i++)
23         {
24             t1[i]=tt[i];
25             t2[i]=tt[i+len];
26         }
27         t1[len]='\0';
28         t2[len]='\0';
29         if (strcmp(t1,s1)==0 && strcmp(t2,s2)==0) break;
30     }
31     return -1;
32 }
33 
34 int main()
35 {
36     scanf("%d",&n);
37     for (int t=1;t<=n;t++)
38     {
39         scanf("%d %s %s %s",&len,s1,s2,ss);
40         printf("%d %d\n",t,f());
41     }
42     return 0;
43 }

 

转载于:https://www.cnblogs.com/NicoleLam/p/4147613.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值