Topic links
Test instructions: There are two strings s1,s2; cross ask whether to get the string s, cannot output-1, can cross the number of outputs
Each reorganization of the string is S2 start, re-assemble, the front half is S1, the latter half S2;
#include <stdio.h>#include<vector>#include<iostream>#include<string.h>#include<algorithm>#include<map>#defineN 250using namespacestd;intMain () {intT, t=1, N, ans, J; scanf ("%d", &T); while(t--) { Chars1[n]={0}, s2[n]={0}, s[n]={0}, str[n]={0};//remember to initialize;map<string,int>maps;//A value that a person understands as a string; intFlag =0; scanf ("%d", &N); scanf ("%s%s%s", S1, S2, s); Ans=0; while(1) {ans++; J=0; for(intI=0; i<n; i++) {str[j++] =S2[i]; Str[j++] =S1[i]; } S[j]=' /'; if(strcmp (str, s) = =0) Break; if(maps[str]==1) {flag=1; Break;}//lead to circulation;maps[str]=1;//have existed;strncpy (s1, str, n); strncpy (S2,str+n, N);//update s1,s2; } if(flag==1) printf ("%d-1\n", t++); Elseprintf ("%d%d\n", t++, ans); } return 0;}
Shuffle ' m Up---poj3087