PTA(Advanced Level)1050.String Subtraction
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的更多相关文章
- PAT (Advanced Level) 1050. String Subtraction (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- PAT 1050 String Subtraction
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- 1050 String Subtraction (20 分)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be the ...
- pat 1050 String Subtraction(20 分)
1050 String Subtraction(20 分) Given two strings S1 and S2, S=S1−S2 is defined to be the ...
- PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- PAT甲级——1050 String Subtraction
1050 String Subtraction Given two strings S1 and S2, S=S1−S2 is defined to be the remain ...
- 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 ...
- 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 ...
随机推荐
- MySQL Index 索引提示:force or use
一.使用索引提示(Index Hint)的条件 1.Mysql优化器错误的选择了某个索引.这种情况很少发生,需要做数据库的表.索引的统计分析. 2.某个SQL语句可选择的索引非常多,这个时候优化器执行 ...
- 第十七节:Runnable创建线程,Thread创建线程,唤醒线程和计数器多线程,线程同步与等待
Runnable创建线程 public class RunnableDemo implements Runnable{ @Override public void run(){ int i = 1; ...
- 省市县数据(txt)
下载地址:https://pan.baidu.com/s/1x1uR9KxzlxAbn5bgN6ZfrQ 提取码:ky8z
- springboot的注解
1.@ConfigurationProperties 功能:装载配置文件信息到实体 原理:aop,通知类型:?(方法或对象创建完后) 注意:作用于方法上可以不需要改源码(例如durid配置) 转载:h ...
- linux 后台 运行
但是如果终端关闭的话,程序也会终止,那么就要涉及到linux的一个十分强大的命令:screen. 按照我个人的理解,这个命令就是能够在linux中创造出多个终端,在已有的窗口内部再创造更多的窗口,结合 ...
- Airbnb架构要点分享——阅读心得
目前,Airbnb已经使用了大约5000个AWS EC2实例,其中大约1500个实例用于部署其应用程序中面向Web的部分,其余的3500个实例用于各种分析和机器学习算法.而且,随着Airbnb的发展, ...
- Centos 6 can't found command subscription-manager
[root@localhost ~]# subscription-manager: command not found-bash: -bash:: command not found resoluti ...
- ArcGIS超级工具SPTOOLS-锐角检查,获得内角并判断是否凸多边形,获得线(面)两个折点方向
1.1 锐角检查 操作视频: https://weibo.com/tv/v/HCNNXhm5F?fid=1034:4392479009475111 可以是面.线夹角锐角检查 输出锐角点的位置和角度( ...
- I am a legend: Hacking Hearthstone with machine-learning Defcon talk wrap-up
I am a legend: Hacking Hearthstone with machine-learning Defcon talk wrap-up: video and slides avail ...
- 安装mysql后必须要做的一件事
Step 1. 检查默认账户和密码 $cat /etc/mysql/debian.cnf # 在ubuntu下查看默认账户名和密码 会看到 [client] host = localhost user ...