乐逍遥xwl

导航

1093 字符串A+B

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

输入格式:

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

输出格式:

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

输入样例:

This is a sample test
to show you_How it works

输出样例:

This ampletowyu_Hrk
 
思路:直接book数组标记解决,不用考虑去重,nice......
 
 1 #include<stdio.h>
 2 #include<math.h>
 3 #include<string.h>
 4 #include<stdlib.h>
 5 int main()
 6 {
 7     int book[130];
 8     char str1[1000001],str2[1000001];
 9     gets(str1);
10     gets(str2);
11     int len1=strlen(str1);
12     int len2=strlen(str2);
13     for(int i=0;i<len1;i++)
14     {
15         if(book[str1[i]]==0)
16         {
17             printf("%c",str1[i]);
18             book[str1[i]]=1;
19         }
20     }
21     for(int i=0;i<len2;i++)
22     {
23         if(book[str2[i]]==0)
24         {
25             printf("%c",str2[i]);
26             book[str2[i]]=1;
27         }
28     }
29     return 0;
30 }

 

 

posted on 2019-03-07 16:06  乐逍遥xwl  阅读(121)  评论(0编辑  收藏  举报