POJ 3087 Shuffle'm Up(水题)

题目链接

蒙姐跟我说了题意,就很简单了,类似打扑克中的插牌。磕磕绊绊,终于把POJ第三次训练刷完了。

 1 #include <cstdio>

 2 #include <cstring>

 3 #include <cmath>

 4 #include <string>

 5 #include <map>

 6 #include <algorithm>

 7 using namespace std;

 8 char s1[101],s2[101],aim[201],str[201];

 9 map<string,int> mp;

10 int main()

11 {

12     int t,n,i,j,ans,num = 1;

13     scanf("%d",&t);

14     while(num <= t)

15     {

16         scanf("%d",&n);

17         scanf("%s%s%s",s1,s2,aim);

18         ans = 1;

19         printf("%d ",num++);

20         while(1)

21         {

22             j = 0;

23             for(i = 0; i < n; i ++)

24             {

25                 str[j++] = s2[i];

26                 str[j++] = s1[i];

27             }

28             str[j] = '\0';

29             if(strcmp(aim,str) == 0)

30             {

31                 printf("%d\n",ans);

32                 break;

33             }

34             if(mp[str])

35             {

36                 printf("-1\n");

37                 break;

38             }

39             else

40             mp[str] = 1;

41             for(i = 0;i < n;i ++)

42             {

43                 s1[i] = str[i];

44             }

45             for(i = 0;i < n;i ++)

46             {

47                 s2[i] = str[i+n];

48             }

49             ans ++;

50         }

51     }

52     return 0;

53 }

 

你可能感兴趣的:(shuffle)