题目
给定两个字符串 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
分析:
用数组来下标来表示字符的ASCII ,用存入数组元素的0和1来确定字符是否已经输入,如果已经输入,则跳过;如果字符之前没有输入,则保存并输出。
代码:
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int arr[127]={0},i;
char c;
for(i=0;i<2;i++){
while((c=getchar())!='\n'){
if(arr[c]==0){
arr[c]=1;
printf("%c",c);
}
}
}
return 0;
}