PAT basic 1093 字符串A+B (20分) C++

一、题目描述

给定两个字符串 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

二、代码

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdlib.h>
using namespace std;
//1093

int main()
{
	bool a[95] = {false};//32-126的字符
	bool b=false;//空格
	char temp = getchar();
	while (temp != '\n')
	{
		if(temp==' ')
			if (b == false)
			{
				b = true;
				cout << temp;
			}
			else;
		else
		{
			if (a[temp - 32] == false)
			{
				a[temp-32] = true;
				cout << temp;
			}
		}
		temp = getchar();
	}
	temp = getchar();
	while (temp != '\n')
	{
		if (temp == ' ')
			if (b == false)
			{
				b = true;
				cout << temp;
			}
			else ;
		else
		{
			if (a[temp - 32] == false)
			{
				a[temp - 32] = true;
				cout << temp;
			}
		}
		temp = getchar();
	}
	system("pause");
	return 0;
}

三、运行结果

在这里插入图片描述

题目合集

在这里呦~

发布了42 篇原创文章 · 获赞 0 · 访问量 745

猜你喜欢

转载自blog.csdn.net/qq_44352065/article/details/104073515
今日推荐