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. fckeditor实现ctrl+v粘贴word图片并上传

    tinymce是很优秀的一款富文本编辑器,可以去官网下载.https://www.tiny.cloud 这里分享的是它官网的一个收费插件powerpaste的旧版本源码,但也不影响功能使用. http ...

  2. CSS定位中“父相子绝”

    一.定位的介绍 定位有三种:相对定位(position:relative).绝对定位(position:absolute).固定定位(position:fixed) 二.三种定位的用法,特点和实例 2 ...

  3. 利用chrome devtool 观察页面占用内存

    推荐阅读:解决内存问题 1. 任务管理器 我们看看下面这幅图: 内存占用空间:原生内存,Dom节点就是存在原生内存里面的. Javascript使用的内存:代表JS堆内存,我们只需要关心括号里面的值( ...

  4. python 将IP地址转换成打包后的32位格式

    python 2.7 #!/usr/bin/env python # Python Network Programming Cookbook -- Chapter - # This program r ...

  5. Feeding Chicken

    D - Feeding Chicken 从左上角开始,往右下角开始遍历,但是遍历的时候需要注意一点,就是遍历的时候需要连起来,就比如第一行从左往右进行遍历,但是第二行不能从左往右了,因为这样就分开了, ...

  6. 关于mysql数据库远程访问

    mysql数据库安装默认为只能本地访问,若需远程连接需根据不同的操作系统做一些操作 Windows: 新装的mysql本地无法登录,显示为1045错误 mysql#1045(1045Access de ...

  7. 自己写了个简单的redis分布式锁【我】

    自己写了个简单的redis分布式锁 [注意:此锁需要在每次使用前都创建对象,也就是要在线程内每次都创建对象后使用] package redis; import java.util.Collection ...

  8. cmake log

    20:28:54: 为项目RoboticArmProject_CarTerminal_V20190530执行步骤 ...20:28:54: 正在启动 "/usr/bin/make" ...

  9. layoutSubviews在以下情况下会被调用

    1.init初始化不会触发layoutSubviews2.addSubview会触发layoutSubviews3.设置view的Frame会触发layoutSubviews,当然前提是frame的值 ...

  10. MLN Alchemy

    1. 前言: 本文主要参考Alchemy Tutorial, washington主页上挂出的所有Alchemy项目(包括Alchemy1.0, Alchemy2.0, AlchemyLite)都无法 ...