#include <iostream>
#include <string>
#include <map>
using namespace std;
//抄博友好程序 用set巧妙 运行一下博友程序
//AHAH A在最低部
map<string,int>mp;
int main()
{
int n;
cin>>n;
//cout<<n<<endl;
int ca=0;
while(n!=0)
{
mp.clear();
n--;
ca++;
int c;
cin>>c;
//cout<<c<<endl;
string s1,s2;
cin>>s1>>s2;
//cout<<s1<<endl<<s2<<endl;
string s;
cin>>s;
//cout<<s<<endl;
int js=0;
string ts;
ts.clear();
string ta,tb;
ta.clear();
tb.clear();
ta=s2;//抄博友程序 学好英语
tb=s1;//抄博友程序
//ta=s1;
//tb=s2;
int flag=0;
while(1)
{
if(ts==s)
{
break;
}
js++;
ts.clear();
for(int i=0;i<c;i++)
{
ts=ts+ta[i];
ts=ts+tb[i];
}
//cout<<ts<<endl;
ta=ts.substr(c,c);
tb=ts.substr(0,c);
//cout<<ta<<endl;
//cout<<tb<<endl;
//if((ta==s1)&&(tb==s2))//博友程序巧妙
if(mp[ts]==1)//抄博友程序 巧妙 学map用法
{
flag=1;
break;
}
mp[ts]=1;
}
cout<<ca<<" ";
if(flag==1)
{
cout<<-1<<endl;
}else
{
cout<<js<<endl;
}
}
return 0;
}
POJ 3087 Shuffle‘m Up 模拟 G++
于 2017-07-11 19:14:46 首次发布