Given two strings A and B, this question requires you to output A+B, which is the union of the two strings. It is required to output A first, and then output B, but repeated characters must be removed .
Input format:
Input A and B are respectively given in two lines, both of which are non-empty character strings whose length does not exceed 106, are composed of visible ASCII characters (that is, the code value is 32~126) and spaces, and are terminated by a carriage return.
Output format:
Output the sum of A and B required by the title on one line.
Input sample:
This is a sample test
to show you_How it works
Sample output:
This ampletowyu_Hrk
The key point of the topic is to eliminate repeated characters . First, declare a string variable c to connect a and b together, and then output the same characters only once.
#include<bits/stdc++.h>
using namespace std;
int main()
{
int vis[127] = {};
string a,b;
getline(cin,a);
getline(cin,b);
string s = a+b;
for(auto x : s){//能访问字符x对应的下标
if(vis[x]==0){
cout<<x;//保证相同的字符只输出一次
vis[x] = 1;
}
}
return 0;
}