PAT A1050 String Subtraction (20分)

题目链接https://pintia.cn/problem-sets/994805342720868352/problems/994805429018673152

题目描述
Given two strings S​1​​ and S​2​​ , S=S​1​​ −S​2​​ is defined to be the remaining string after taking all the characters in S​2​​ from S​1​​ . Your task is simply to calculate S​1​​ −S2​​ for any given strings. However, it might not be that simple to do it fast.

输入
Each input file contains one test case. Each case consists of two lines which gives S​1​​ and S​2​​ , respectively. The string lengths of both strings are no more than 10​4​​ . It is guaranteed that all the characters are visible ASCII codes and white space, and a new line character signals the end of a string.

输出
For each test case, print S​1​​ −S​2​ in one line.

样例输入
They are students.
aeiou

样例输出
Thy r stdnts.

代码

#include <iostream>
#include <string>
using namespace std;

int main() {
	string s1, s2;
	int hash[200] = {0};
	getline(cin, s1);
	getline(cin, s2);
	for(int i = 0; i < s2.size(); i++)
		hash[s2[i]] = 1;
	for(int i = 0; i < s1.size(); i++) {
		if(hash[s1[i]] == 0)
			cout << s1[i];
	}
	cout << endl;	
}
发布了288 篇原创文章 · 获赞 12 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/Rhao999/article/details/104669259