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. PHP mysqli_close() 函数

    关闭先前打开的数据库连接: <?php $con=mysqli_connect("localhost","my_user","my_passwo ...

  2. 002_UCOSIII任务创建于删除

    (一)先创建一个启动任务来进行创建其它任务,创建任务的宏定义 #define START_TASK_PRIO 3 //任务优先级 #define START_STK_SIZE 128 //任务堆栈大小 ...

  3. 018_STM32程序移植之_串口接收中文

    (一)在平时数据传输中很少用到接收中文的情况,但是最近需要用到就花了半天时间来弄弄 (二)接收原理,从现在接收情况分析:一个中文占两个数据的空间,也就是两个十六进制可以转化成为一个中文 (三)示例情况 ...

  4. ckeditor粘贴word图片自动上传功能

    由于工作需要必须将word文档内容粘贴到编辑器中使用 但发现word中的图片粘贴后变成了file:///xxxx.jpg这种内容,如果上传到服务器后其他人也访问不了,网上找了很多编辑器发现没有一个能直 ...

  5. CF 940F - Machine Learning ( 带 修 )

    题目: 链接:https://codeforces.com/problemset/problem/940/F 题意:给你n个数,a[i]有q个操作,操作有两种:操作1.       1 x y 表示询 ...

  6. 题解 CF550A 【Two Substrings】

    为什么我的做法跟别人如此不一样啊qwq 思路:暴力判每一个"BA"出现的位置,二分查找他前/后有没有满足条件的"AB",时间复杂度\(O(n\log_{2}n) ...

  7. 【线性代数】7-2:线性变化的矩阵(The Matrix of a Linear Transformation)

    title: [线性代数]7-2:线性变化的矩阵(The Matrix of a Linear Transformation) categories: Mathematic Linear Algebr ...

  8. oc Learning Blog

    http://www.cnblogs.com/heyonggang/p/3351269.html M了个J :http://www.cnblogs.com/mjios/tag/objective-c/ ...

  9. POJ 1661 Help Jimmy ——(记忆化搜索)

    典型的记忆化搜索问题,dfs一遍即可.但是不知道WA在哪里了= =,一直都没找出错误.因为思路是很简单的,肯定是哪里写挫了,因此不再继续追究了. WA的代码如下,希望日后有一天能找出错误= =: —— ...

  10. ORM SQLAlchemy - 建立一个关系 relationship

    relationship函数是sqlalchemy对关系之间提供的一种便利的调用方式, backref参数则对关系提供反向引用的声明 1 背景 如没有relationship,我们只能像下面这样调用关 ...