1093. 字符串A+B (20 分)

给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集。要求先输出 A,再输出 B,但重复的字符必须被剔除

输入格式:

输入在两行中分别给出 A 和 B,均为长度不超过 10​6​​的、由可见 ASCII 字符 (即码值为32~126)和空格组成的、由回车标识结束的非空字符串。

输出格式:

在一行中输出题面要求的 A 和 B 的和。

输入样例:

This is a sample test
to show you_How it works

输出样例:

This ampletowyu_Hrk
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<stdlib.h>
const int MAX=1e6;
char a[2*MAX],b[MAX];
using namespace std;
int main()
{
	int ch[500]={0};

	fgets(a,2*MAX,stdin);
	int len = strlen(a);
	if(a[len-1]=='\n'&&a[len]=='\0') 
	{
	    a[len-1]='\0';
	}
	fgets(b,MAX,stdin);
	len=strlen(b);
	if(b[len-1]=='\n'&&b[len]=='\0') 
	{
	    b[len-1]='\0';
	}
	strcat(a,b);
	int length=strlen(a);
	for(int i=0;i<length;i++)
	{
		if(!ch[a[i]])
		{
			printf("%c",a[i]);
			ch[a[i]]=1;
		}
	}
	return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

风间琉璃c

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值