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. Oracle 物理结构(七) 文件-归档日志文件

    Oracle 物理结构(七) 文件-归档日志文件

  2. luoguP3366 【模板】最小生成树 x

    P3366 [模板]最小生成树 2.4K通过 6.3K提交 题目提供者HansBug 标签 云端↑ 生成树 难度 普及- 时空限制 1s / 128MB 题目描述 如题,给出一个无向图,求出最小生成树 ...

  3. Dockerfile创建tomcat和jdk,并发布java项目

    1.准备好需要的jdk 和 tomcat kun@ubuntu:~$ cd tomcat-docker/ kun@ubuntu:~/tomcat-docker$ ll total drwxrwxr-x ...

  4. Win10配置Java环境变量

    很多同学在学习Java入门的时候被Java环境变量搞的一头雾水,今天这篇文章拓薪教育就来说一下如何在win10下配置环境变量; 下载jdk安装包: 首先我们需要下载jdk的安装包,这里提供jdk的安装 ...

  5. 十六、程序包管理之 rpm

    c语言程序的构建过程 1.程序源代码 --> 预处理 --> 编译 --> 汇编 --> 链接--> 可执行程序 开放源码:就是程序码,文本格式的源代码,写给人类看的程序 ...

  6. Robot Framework(十八) 支持工具

    5支持工具 5.1库文档工具(libdoc) libdoc是一种用于为HTML和XML格式的测试库和资源文件生成关键字文档的工具.前一种格式适用于人类,后者适用于RIDE和其他工具.Libdoc也没有 ...

  7. ICEM—倾斜孔

    原视频下载:https://yunpan.cn/cS3UGMEscrYpL  访问密码 839b

  8. sql注入笔记-mysql

    整理下sql相关知识,查漏补缺(长期更新) 1 常用语句及知识 information_schema包含了大量有用的信息,例如下图 mysql.user下有所有的用户信息,其中authenticati ...

  9. 黑马vue---40、结合Node手写JSONP服务器剖析JSONP原理

    黑马vue---40.结合Node手写JSONP服务器剖析JSONP原理 一.总结 一句话总结: 服务端可以返回js代码给script标签,那么标签会执行它,并且可带json字符串作为参数,这样就成功 ...

  10. Flume-自定义 Sink

    Sink 不断地轮询 Channel 中的事件且批量地移除它们,并将这些事件批量写入到存储或索引系统.或者被发送到另一个 Flume Agent. Sink 是完全事务性的. 在从 Channel 批 ...