HDU 5264 pog loves szh I

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5264


题面:

pog loves szh I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 420    Accepted Submission(s): 288


Problem Description
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.
 

Input
The first line has an integer,  T(1T100) , 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').
 

Output
For each cases, please output two lines, indicating two original strings.
 

Sample Input
   
   
   
   
1 aabbca
 

Sample Output
   
   
   
   
abc aba For example, there are two strings: "abcd" and "efgh". After mixing, a new string "aebfcgdh" is coming.
 

Source
BestCoder Round #43
 

Recommend
hujie   |   We have carefully selected several similar problems for you:   5275  5274  5273  5271  5270 
 

解题:简单的字符串处理。


代码:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	int n,len;
	cin>>n;
	string s,x,y;
	while(n--)
	{
		cin>>s;
		x="";
		y="";
		len=s.length();
		for(int i=0;i<len;i++)
		{
			if(i&1)
			{
				y+=s[i];
			}
			else x+=s[i];
		}
		reverse(y.begin(),y.end());
		cout<<x<<endl;
		cout<<y<<endl;
	}
	return 0;
} 


你可能感兴趣的:(入门,HDU,BestCoder)