给定两个字符串 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
这道题 正常写就行,用map来标记字符出现的次数,如果出现一次,放到vector中。最后输出
我的代码如下
#include<string>
#include <iostream>
#include<map>
#include<vector>
using namespace std;
int main()
{
map<char, int>mp1;
map<char, int>mp2;
vector<char> vcchar;
string a,b;
getline(cin, a);
getline(cin, b);
for (int i = 0; i < a.size(); i++)
{
mp1[a[i]]++;
if (mp1[a[i]] == 1)
{
vcchar.push_back(a[i]);
}
}
for (int i = 0; i < b.size(); i++)
{
mp1[b[i]]++;
if (mp1[b[i]] == 1)
{
vcchar.push_back(b[i]);
}
}
for (const char& c : vcchar)
{
cout << c;
}
cout << endl;
}