标签:
http://acm.hdu.edu.cn/showproblem.php?pid=5264
Pog has lots of strings. And he always mixes two equal-length strings. For example, there are two strings: "abcd" and "efgh". After mixing, a new string "aebfcgdh" is coming.
However, szh thinks it is boring, so he reverses the second string, like changing "efgh" to "hgfe". Then mix them as usual, resulting in "ahbgcfde".
Now, here comes a problem. Pog is given a string after mixing by szh, but he wants to find the original two strings.
Hint : In this question, it needs a linefeed at the end of line at hack time.
The first line has an integer, $T(1 \leq T \leq 100)$, indicating the number of cases.
Then follows T lines. Every lines has a string S, whose length is even and not more than 100, and only consists of lower-case characters(‘a‘~‘z‘).
For each cases, please output two lines, indicating two original strings.
1
aabbca
abc
aba
For example, there are two strings: "abcd" and "efgh". After mixing, a new string "aebfcgdh" is coming.
1 #include<algorithm> 2 #include<iostream> 3 #include<string> 4 using std::cin; 5 using std::cout; 6 using std::endl; 7 using std::string; 8 int main() { 9 #ifdef LOCAL 10 freopen("in.txt", "r", stdin); 11 freopen("out.txt", "w+", stdout); 12 #endif 13 std::ios::sync_with_stdio(false); 14 int t; 15 cin >> t; 16 while (t--) { 17 string s1, s2, buf; 18 cin >> buf; 19 for (int i = 0; buf[i]; i++) { 20 if (i & 1) s2 = buf[i] + s2; 21 else s1 += buf[i]; 22 } 23 cout << s1 << endl << s2 << endl; 24 } 25 return 0; 26 }
标签:
原文地址:http://www.cnblogs.com/GadyPu/p/4561480.html