Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

map判环+模拟

Posted by qq1250173534 at 2020-03-02 13:59:57 on Problem 3087
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator