hdu 5264 pog loves szh I 水题

pog loves szh I

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5264

Description

pog拥有很多字符串,它喜欢将两个长度相等字符串交错拼在一起,如abcd与efgh,那么交错拼在一起就成了aebfcgdh啦!
szh觉得这并不好玩,因此它将第二个字符串翻转了一遍,如efgh变成了hgfe,然后再将这两个字符串交错拼在一起,因此abcd与efgh就成了ahbgcfde啦!
现在问题来了,pog手里有一个由szh亲手拼好的字符串,它想还原出原来的两个字符串,出于szh对pog的爱,szh帮助pog还原出了原来的两个字符串。

Input

第一行读入一个整数T(1≤T≤100),表示有T组数据。
接下来T行每行读入一个长度为偶数且仅包含英文小写字母的字符串(|S|≤100)。

Output

对于每组数组,输出两行,表示原来的两个字符串。

Sample Input

1
aabbca

Sample Output

abc
aba

HINT

题意

题解:

读入一个串,第一个字符串首先将指针指向0,然后每次将指针+2输出即可。第二个字符串首先将指针指向n−1,然后每次将指针−2,输出即可。
注意题目中描述的是第二个字符串经过翻转才得到读入的字符串的。

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)  
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[20];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
    ll x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline void P(int x)
{
    Num=0;if(!x){putchar('0');puts("");return;}
    while(x>0)CH[++Num]=x%10,x/=10;
    while(Num)putchar(CH[Num--]+48);
    puts("");
}
//**************************************************************************************

int main()
{
    //test;
    int t=read();
    while(t--){
    string s,s1,s2;
    cin>>s;
    for(int i=0;i<s.size();i+=2)
        s1+=s[i];
    for(int i=s.size()-1;i>=0;i-=2)
        s2+=s[i];
    cout<<s1<<endl;
    cout<<s2<<endl;
    }
}
原文地址:https://www.cnblogs.com/qscqesze/p/4561417.html