PAT1050 : String Subtraction

Posted 0kk470

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PAT1050 : String Subtraction相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

PAT (Advanced Level) 1050. String Subtraction (20)

PAT Advanced 1050 String Subtraction (20 分)

PAT甲题题解-1050. String Subtraction (20)-水题

PAT Advanced 1050 String Subtraction (20) [Hash散列]

PAT甲级1050 String Subtraction (20 分)

PAT练习--1050 String Subtraction (20 分)