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 ...
随机推荐
- aspnet_regiis命令使用
1.使用aspnet_regiis.exe加密web.config文件 http://www.cnblogs.com/MinSentinel/archive/2008/08/01/1258168.ht ...
- mkswap/swapon/swapoff/free
free mkswap 创建Linux交换分区 swapon 启用交换分区 swapoff 关闭交换分区 注意: 在创建完交换区之后.是需要激活才能使用的 swapon/swapoff
- GitLab 如何删除 Forked from
在 GitLab 中有 Forked from. 如何删除这个? 在 Settings 中选择 General 然后选择 Advanced 高级选项 然后单击移除 fork 关系的选项,你就可以将这个 ...
- 关于openstack 网络相关的文章收集
journalctl工具基础介绍(你需要这个的.) https://blog.51cto.com/13598893/2072212 新版devstack使用systemd的方式来管理OpenStack ...
- 爬虫之操作excel
几种常用模块的使用方法 注释:Excel 2003 即XLS文件有大小限制即65536行256列,所以不支持大文件,而Excel 2007以上即XLSX文件的限制则为1048576行16384列 下面 ...
- vue pdf下载
主要技术栈是Vue,两个库: html2canvas npm地址 jspdf 具体实现代码如下: <template> <div class="priview_resume ...
- msql数据库常用指令操作
数据库指令 1.数据库指令 创建数据库:create database db_name; 删除数据库:drop database db_name; 显示数据库:show databases: 导出数据 ...
- Django module
1,模型定义 models.py的例子: class Author(models.Model): name=models.CharField(max_length=20) class Book(mod ...
- Linux命令:hexdump
hexdump是Linux下的一个二进制文件查看工具,它可以将二进制文件转换为ASCII.八进制.十进制.十六进制格式进行查看. 指令所在路径:/usr/bin/hexdump 命令语法: hexdu ...
- 移动端—— 兼容PC端,移动端的点击事件
移动设备上不支持鼠标事件,好在webkit内核的移动浏览器支持 touch 事件,所以触摸事件是移动应用中所必须的.touchstart.touchmove.touchend事件可以类比于moused ...