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的字符,再扫描一遍S2,确定不可用的字符
  • 最后扫描一遍S1,如果对应的字符可用就输出
代码
#include<bits/stdc++.h>
using namespace std; int main()
{
string s1, s2;
getline(cin, s1);
getline(cin, s2);
map<char,int> mp;
for(int i=0;i<s1.size();i++)
if(mp.count(s1[i]) == 0)
mp[s1[i]] = 1;
for(int i=0;i<s2.size();i++)
if(mp.count(s2[i]) == 0) //该字符根本没有在s1中出现过
continue;
else
mp[s2[i]] = 0; //标记为0表示不可用
for(int i=0;i<s1.size();i++)
if(mp[s1[i]] != 0)
cout << s1[i];
return 0;
}
引用

https://pintia.cn/problem-sets/994805342720868352/problems/994805429018673152

PTA(Advanced Level)1050.String Subtraction的更多相关文章

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

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  2. PAT 解题报告 1050. String Subtraction (20)

    1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...

  3. PAT 1050 String Subtraction

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  4. 1050 String Subtraction (20 分)

    1050 String Subtraction (20 分) Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the ...

  5. pat 1050 String Subtraction(20 分)

    1050 String Subtraction(20 分) Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the ...

  6. PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  7. PAT甲级——1050 String Subtraction

    1050 String Subtraction Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remain ...

  8. PTA(Advanced Level)1036.Boys vs Girls

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  9. PTA (Advanced Level) 1040 Longest Symmetric String

    1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the lo ...

随机推荐

  1. mouseout([[data],fn])

    mouseout([[data],fn]) 概述 当鼠标指针从元素上移开时,发生 mouseout 事件. 该事件大多数时候会与 mouseover 事件一起使用.深圳dd马达 注释:与 mousel ...

  2. BSGS ! x

    一.引入: 若存在一个式子a^b ≡ c (mod p) (p ≡ 1000000007,且0<a,b,c<p) 已知a,b,求c.  这不就是快速幂嘛! 已知a,c,求b. 这就是我们需 ...

  3. adb的一些命令

    adb pull <手机路径> <本机路径> 从手机中拉取信息到本地电脑上 adb push <本机路径> <手机路径> 从本地电脑推送信息到手机上

  4. 安装VMware虚拟机和centos操作系统

    1,安装包:百度网盘: 2,安装教程:https://blog.csdn.net/qq_31362105/article/details/80706096  配置好操作系统,内存,网络等: 3,Cen ...

  5. go -- application/x-www-form-urlencoded发送post数据

  6. CodeWar打怪升级-Python篇

    1.  The goal of this exercise is to convert a string to a new string where each character in the new ...

  7. Mac 上卸载node和npm

    Mac 上卸载node和npm 卸载node依次在终端执行下面的脚本 sudo npm uninstall npm -gsudo rm -rf /usr/local/lib/node /usr/loc ...

  8. <JavaScript> call()、apply()、bind() 的用法

    其实是一个很简单的东西,认真看十分钟就从一脸懵B 到完全 理解! 先看明白下面: 例 1 obj.objAge; obj.myFun() // 小张年龄 undefined   例 2 shows() ...

  9. springboot之JWT实现权限认证

    1.在pom.xml添加依赖 <dependency> <groupId>com.auth0</groupId> <artifactId>java-jw ...

  10. Sql题目精选练习

    1.每日经典sql 1.1.1 根据三张关系表查询雇员中工资最高的雇员的员工姓名.工资和部门号. salary(工资表) employee(员工表) department(部门表) Sql语句: SE ...