1093 字符串A+B (20分)
输入样例:
This is a sample test
to show you_How it works
输出样例:
This ampletowyu_Hrk
思路:
1.先求并集,然后从A开始,每个在并集里的字符输出且仅输出一次
首次通过代码:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<string.h> 3 4 int main(){ 5 char a[1000005]; 6 char b[1000005]; 7 int a1[128]={0}; 8 int b1[128]={0}; 9 gets(a); 10 gets(b); 11 for(int i=0;i<strlen(a);i++) 12 if(a1[a[i]]==0) a1[a[i]]=1; 13 for(int i=0;i<strlen(b);i++) 14 if(a1[b[i]]==0) a1[b[i]]=1; 15 for(int i=0;i<strlen(a);i++) 16 if(a1[a[i]]==1&&b1[a[i]]==0) { 17 printf("%c",a[i]); 18 b1[a[i]]=1; 19 } 20 for(int i=0;i<strlen(b);i++) 21 if(a1[b[i]]==1&&b1[b[i]]==0) { 22 printf("%c",b[i]); 23 b1[b[i]]=1; 24 } 25 26 return 0; 27 }