Strings with the Same Length

题目描述

Given are strings s and t of length N each, both consisting of lowercase English letters.
Let us form a new string by alternating the characters of S and the characters of T, as follows: the first character of S, the first character of T, the second character of S, the second character of T, ..., the N-th character of S, the N-th character of T. Print this new string.

Constraints
·1≤N≤100
·|S|=|T|=N
·S and T are strings consisting of lowercase English letters.

输入

Input is given from Standard Input in the following format:

N
S T

输出

Print the string formed.

样例输入 Copy

【样例1】
2
ip cc
【样例2】
8
hmhmnknk uuuuuuuu
【样例3】
5
aaaaa aaaaa

样例输出 Copy

【样例1】
icpc
【样例2】
humuhumunukunuku
【样例3】
aaaaaaaaaa

这道题要AC起来十分简单,不要被题目迷惑了,傻傻地建立两个字符串,只需要建立一个字符数组 即可。根据题目我们可以得知,第一个字符串是放在奇数位置的,第二个字符串是放在偶数位置的。那么我们就把字符数组的奇数位置输入第一个字符串的信息,偶数位置输入第二个字符串的信息,在打印输出字符数组即可。

AC代码:

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	char a[201];
	int n;
	cin>>n;
	for(int i=0;i<2*n;i+=2)
		cin>>a[i];
	for(int j=1;j<2*n;j+=2)
		cin>>a[j];
	for(int i=0;i<2*n;i++)
	cout<<a[i];
	return 0;
}

以上是个人小白的见解,如有更好解法,请指教!

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值