码迷,mamicode.com
首页 > 其他好文 > 详细

PAT1050 : String Subtraction

时间:2017-10-04 15:53:10      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:oat   contains   文本对比   pat   lin   sts   string   限制   ons   

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

标签:oat   contains   文本对比   pat   lin   sts   string   限制   ons   

原文地址:http://www.cnblogs.com/0kk470/p/7625663.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!