PAT_A1050#String Subtraction

Source:

PAT A1050 String Subtraction (20 分)

Description:

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​​−S​2​​ 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 S​1​​ and S​2​​, respectively. The string lengths of both strings are no more than 1. 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 S​1​​−S​2​​ in one line.

Sample Input:

They are students.
aeiou

Sample Output:

Thy r stdnts.

Keys:

Code:

 1 /*
 2 Data: 2019-07-21 19:47:24
 3 Problem: PAT_A1050#String Subtraction
 4 AC: 08:34
 5 
 6 题目大意:
 7 给定字符串S和T,把T中的字符从S中删去
 8 */
 9 
10 #include<cstdio>
11 #include<string>
12 #include<iostream>
13 using namespace std;
14 char mp[128]={0};
15 
16 int main()
17 {
18 #ifdef    ONLINE_JUDGE
19 #else
20     freopen("Test.txt", "r", stdin);
21 #endif
22 
23     string s,t;
24     getline(cin,s);
25     getline(cin,t);
26     for(int i=0; i<t.size(); i++)
27         mp[t[i]]=1;
28     for(int i=0; i<s.size(); i++)
29         if(mp[s[i]]==0)
30             printf("%c", s[i]);
31 
32     return 0;
33 }

 

 

 

 

 

 

Given two strings S1 and S2S=S1S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1S2 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 1. 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 S1S2 in one line.

Sample Input:

They are students.
aeiou

Sample Output:

Thy r stdnts.
posted @ 2019-07-21 20:00  林東雨  阅读(205)  评论(0编辑  收藏  举报