poj 3087
Posted Tartarus
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poj 3087相关的知识,希望对你有一定的参考价值。
\\(string\\) 的简单应用
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 110;
int T, n;
map<string, bool> mp;
ll read(){ ll s = 0, f = 1; char ch = getchar(); while(ch < \'0\' || ch > \'9\'){ if(ch == \'-\') f = -1; ch = getchar(); } while(ch >= \'0\' && ch <= \'9\'){ s = s * 10 + ch - \'0\'; ch = getchar(); } return s * f; }
int main(){
T = read();
for(int t = 1 ; t <= T ; ++t){
string s1, s2, res, tmp;
cin >> n >> s1 >> s2 >> res;
mp.clear();
map<string, bool>::iterator ite;
int cnt = 0;
while(1){
tmp = "";
for(int i = 0 ; i < n ; ++i){
tmp = tmp + s2[i] + s1[i];
}
++cnt;
ite = mp.find(tmp);
if(ite -> second == true){
cout << t << " " << -1 << endl;
break;
}
mp[tmp] = true;
if(tmp == res){
cout << t << " " <<cnt << endl;
break;
}
s1 = tmp.substr(0, n);
s2 = tmp.substr(n);
}
}
return 0;
}
以上是关于poj 3087的主要内容,如果未能解决你的问题,请参考以下文章