1050. String Subtraction (20)

1.给出两个string,下面string中包含的字符,需要在上面的string中删除。

2.这道题需要注意,s1和s2的输入都需要使用getline,避免出现空格的情况。

时间限制
10 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

Given two strings S1 and S2, S = S1 – S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1 – S2 for any given strings. However, it might not be that simple to do it fast.

Input Specification:

Each input file contains one test case. Each case consists of two lines which gives S1 and S2, respectively. The string lengths of both strings are no more than 104. 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.

Output Specification:

For each test case, print S1 – S2 in one line.

Sample Input:

They are students.
aeiou

Sample Output:

Thy r stdnts.

 
AC代码:

//#include<string>
//#include <iomanip>
#include<vector>
#include <algorithm>
//#include<stack>
#include<set>
#include<queue>
#include<map>
//#include<unordered_set>
#include<unordered_map>
//#include <sstream>
//#include "func.h"
//#include <list>
#include<stdio.h>
#include<iostream>
#include<string>
#include<memory.h>
#include<limits.h>
using namespace std;

int main(void)
{

	string s1, s2;
	getline(cin, s1);
	getline(cin, s2);//注意s2也需要geline,可能包括空格
	bool exist[256] = { 0 };
	for (int i = 0; i<s2.size(); i++)
	{
		exist[s2[i]] = true;
	}
	string ans = "";
	for (int i = 0; i<s1.size(); i++)
	{
		if (!exist[s1[i]])
			ans += s1[i];
	}
	cout << ans << endl;
	return 0;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注