POJ - 3087 Shuffle'm Up (模拟)
题目链接:https://vjudge.net/problem/POJ-3087
模拟洗牌的过程
1 #include<iostream> 2 #include<algorithm> 3 #include<string> 4 #include<cstring> 5 #include<cstdio> 6 #include<cmath> 7 #include<stack> 8 #include<queue> 9 #include<map> 10 11 using namespace std; 12 typedef long long ll; 13 const int maxn = 5e4 + 5; 14 const int INF = 0x3f3f3f3f; 15 16 map<string, bool>mp; 17 18 int main() 19 { 20 int t; 21 cin >> t; 22 for (int k = 1; k <= t; k++) { 23 int len; 24 cin >> len; 25 string s1, s2, str, tmp; 26 cin >> s1 >> s2 >> str; 27 int ans = 0, flag = 1; 28 mp.clear(); 29 while (flag) { 30 tmp = ""; 31 for (int i = 0; i < len; i++) { 32 tmp += s2[i]; 33 tmp += s1[i]; 34 } 35 ans++; 36 if (tmp == str) { 37 cout << k << " " << ans << endl; 38 break; 39 } 40 s1 = tmp.substr(0, len); 41 s2 = tmp.substr(len); 42 if (mp[tmp]) { 43 flag = 0; 44 break; 45 } 46 mp[tmp] = true; 47 } 48 if (flag == 0) { 49 cout << k << " " << -1 << endl; 50 } 51 } 52 return 0; 53 }