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 ...
随机推荐
- 002_linuxC++_.h和.c文件
(一)程序修改001_linuxC++之_类的引入 (二)修改成为.h和.c文件 #include <stdio.h> #include "person.h" int ...
- ES6-12.Symbol
Symbol是ES6新增的原始类型数据,引入的初衷是为了对象可以有永不重复的属性名. 所以属性名可以是字符串外,还可以是Symbol值: const a = Symbol("a") ...
- Activiti服务类- HistoryService服务类
转自:https://www.cnblogs.com/liuqing576598117/p/11164027.html 一共个方法15个方法 用于查询历史工作流信息1.创建查询(7个方法)//创建一个 ...
- Active Directory 常用属性
1.获取DirectoryEntry string str = string.Empty; string strPath = @LDAP://testDomain.com.mo; string ad ...
- SP1716 GSS3(线段树+矩阵乘法)
Code: #include <bits/stdc++.h> #define N 50001 #define ll long long #define lson now<<1 ...
- 为什么margin:0 auto不能用于inline-block元素
前言:今天一个实习生问我,为什么他对图片使用了margin:0 auto,但图片却没有居中,我让他换成对父元素使用text-align:center即可.为什么margin:0 auto对图片不起作用 ...
- Public model for matrix
以下是可以加减乘除(就是乘逆矩阵啦)以及求若干次幂.行列式和逆的矩阵模板. 欢迎大家指正其中可能存在的错误(只验证了求逆的正确性). 顺便提一下这种复杂度低于定义式求逆的方法,来自于我的高等代数书,思 ...
- thinkphp5 大量数据批量插入数据库的解决办法
对于数据量很小,怎么玩都是可以的. but!!! 如果有几十万或者百万级别的数据,该怎么处理,请往下面看
- php使用ZipArchive提示Fatal error: Class ZipArchive not found in的解决方法
使用压缩包函数必须要安装zip扩展,否则会报错 $ apt install php-zip
- electron-vue搭建项目
原文链接 使用pdf.js插件与LODOP控件实现前端浏览器静默打印PDF文件 lodop官网地址:http://www.lodop.net/download.html 点击下载,文件里有使用手册 e ...