美文网首页
poj3087 string模拟

poj3087 string模拟

作者: 暖昼氤氲 | 来源:发表于2019-11-28 20:59 被阅读0次
 /*
Time:2019.11.28
Author: Goven
type:string模拟 
err:
ref:
*/
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main()
{
    int n, k, ans;
    string s1, s2, s12, s;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> k >> s1 >> s2 >> s;
        ans = 0;
        map<string, int> mp;
        while (1) {
            s12 = "";
            for (int j = 0; j < k; j++) {
                s12 += s2[j];
                s12 += s1[j];
            }
            ans++;
            if (s12 == s) {
                break;
            }
            if (mp[s12]) {
                ans = -1;
                break;
            }
            mp[s12] = 1;
            s1 = s12.substr(0,k);
            s2 = s12.substr(k,k);
        }
        cout << i << " " << ans << endl;
    }
    
    return 0;
}

相关文章

网友评论

      本文标题:poj3087 string模拟

      本文链接:https://www.haomeiwen.com/subject/sajiwctx.html