PAT (Basic Level) Practice 1093 字符串A+B (20 分)
作者:互联网
题目:1093 字符串A+B (20 分)
来源:PAT (Basic Level) Practice
传送门 1093 字符串A+B
题面
思路:用数组标记a,b中元素的出现,出现即标记为1,然后先遍历a字符串,若该元素未输出,则输出该元素,并将两个标记数组中该元素的值改为0,然后遍历b字符串,同样操作即可。
Code
点击查看代码
#include <iostream>
#include <string>
using namespace std;
int n1[200], n2[200];
int main() {
string a, b;
getline(cin, a);
getline(cin, b);
for (int i = 0; i < a.size(); i++)n1[a[i] - '0'] = 1;
for (int i = 0; i < b.size(); i++)n2[b[i] - '0'] = 1;
for (int i = 0; i < a.size(); i++) {
if (n1[a[i] - '0'] == 1) {
cout << a[i];
n1[a[i] - '0'] = 0;
n2[a[i] - '0'] = 0;
}
}
for (int i = 0; i < b.size(); i++) {
if (n2[b[i] - '0'] == 1) {
cout << b[i];
n2[b[i] - '0'] = 0;
}
}
cout << "\n";
return 0;
}
标签:PAT,1093,int,Practice,++,字符串,n1,size 来源: https://www.cnblogs.com/w0x59-h/p/15852954.html