前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【PAT甲级】String Subtraction

【PAT甲级】String Subtraction

作者头像
喜欢ctrl的cxk
发布2019-11-08 13:43:41
2360
发布2019-11-08 13:43:41
举报
文章被收录于专栏:Don的成长史

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

代码语言:txt
复制
                 本文链接:[https://blog.csdn.net/weixin\_42449444/article/details/88782967](https://blog.csdn.net/weixin_42449444/article/details/88782967) 

Problem Description:

Given two strings

and

, S =

​​​​​​​​​ is defined to be the remaining string after taking all the characters in

​​​​​​​​​ from

​​​​​​​​​. Your task is simply to calculate

​​​​​​​​​−

​​​​​​​ 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

​​​​​​​​​ and

​​, respectively. The string lengths of both strings are no more than 10​4​​. 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

​​−

in one line.

Sample Input:

代码语言:javascript
复制
They are students.
aeiou

Sample Output:

代码语言:javascript
复制
Thy r stdnts.

解题思路:

这道水题跟【GPLT】L1-011 A-B 可以说是一模一样的,上次我是用map求解的,那这次就用set来玩下吧。在字符串A中删除字符串B中含有的字符后输出字符串A-B。换个角度来想就是只输出字符串A中字符串B不含有的字符。

AC代码:

代码语言:javascript
复制
#include <bits/stdc++.h>
using namespace std;

int main()
{
    string s1,s2;
    getline(cin,s1);
    getline(cin,s2);
    set<int> s;   //记录s2中的字符
    for(auto it : s2)
    {
        s.insert(it);
    }
    for(auto it : s1)
    {
        if(s.count(it) == 0)  //避免输出s2中的字符
        {
            cout << it;
        }
    }
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/03/24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Problem Description:
  • Input Specification:
  • Output Specification:
  • Sample Input:
  • Sample Output:
  • 解题思路:
  • AC代码:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档