Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
map判环+模拟#include <iostream> #include <cstring> #include <string> #include <cstdio> #include <map> using namespace std; int main() { int t,n; cin>>t; for(int c = 1;c <= t;c++){ char s1[210],s2[210],ss[410],s[410]; cin>>n>>s1>>s2>>ss; map<string,bool>m; m.clear(); int step = 0; while(true){ int j = 0; for(int i = 0;i < n;i++){ s[j++] = s2[i]; s[j++] = s1[i]; } s[j] = '\0'; step++; if(strcmp(ss,s) == 0){ printf("%d %d\n",c,step); break; } else{ if(m[s] == true){ printf("%d %d\n",c,-1); break; } else{ for(int i = 0;i < n;i++){ s1[i] = s[i]; } s1[n] = '\0'; for(int j = n;j < 2*n;j++){ s2[j-n] = s[j]; } s2[n] = '\0'; m[s] = true; } } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator