1. 程式人生 > >PAT1050 : String Subtraction

PAT1050 : String Subtraction

作者 calculate order length print efi ati style rac

1050. String Subtraction (20)

時間限制 100 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.


思路
水題,map模擬一個字典記錄要刪除的字母,遍歷打印s1時不打印字典上的字母就行。

另外:吐槽一下pat好多題一個文件對應一個測試用例,不像acm一個文件有多個用例需要重復讀取==。

代碼
#include<iostream>
#include<string>
#include<unordered_map>
using
namespace std; int main() { string s1,s2; getline(cin,s1); getline(cin,s2); unordered_map<char,int> dic; for(int i = 0;i <s2.size();i++) { dic.insert(pair<char,int>(s2[i],1)); } for(int i = 0;i < s1.size();i++) { if(dic.count(s1[i]) > 0) continue; else cout << s1[i]; } }

PAT1050 : String Subtraction