1093 字符串A+B (20分)
1093 字符串A+B (20分)
给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集。要求先输出 A,再输出 B,但重复的字符必须被剔除。
输入格式:
输入在两行中分别给出 A 和 B,均为长度不超过 1的、由可见 ASCII 字符 (即码值为32~126)和空格组成的、由回车标识结束的非空字符串。
输出格式:
在一行中输出题面要求的 A 和 B 的和。
输入样例:
This is a sample test
to show you_How it works
输出样例:
This ampletowyu_Hrk
代码讲解:此题我取了个巧,构建了俩个hash,一个是A每个字符的次数,只要出现过,就不输出了,第二个是B的hash
对B来说只要这个字符hash A 没出现过,并且自己 hash也没出现过才能输出。。。
1 #include<stdio.h> 2 int a[128],b[128]; 3 int main() 4 { 5 char temp; 6 while((temp=getchar())!='\n') 7 { 8 if(!a[temp]) 9 { 10 a[temp]=1; 11 putchar(temp); 12 } 13 } 14 while((temp=getchar())!='\n') 15 { 16 if(!b[temp]&&!a[temp]) 17 { 18 b[temp]=1; 19 putchar(temp); 20 } 21 } 22 return 0; 23 }