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 ...
随机推荐
- php中的print函数
php print函数怎么用? 定义和用法 print() 函数输出一个或多个字符串. 注释:print() 函数实际不是一个函数,所以您不必对它使用括号. 提示:print() 函数比 echo() ...
- 002_C/C++笔试题_简单算法程序
(一)冒泡排序法 #include <iostream> using namespace std; void bubblesort(int a[], int m); int main(vo ...
- sql server 复习笔记1
查询数据库是否存在: if DB_ID("testDB")is not null; 检查表是否存在: if OBJECT_ID(“textDB”,“U”) is not null ...
- redis之哨兵集群
一.主从复制背景问题 Redis主从复制可将主节点数据同步给从节点,从节点此时有两个作用: 一旦主节点宕机,从节点作为主节点的备份可以随时顶上来. 扩展主节点的读能力,分担主节点读压力. 但是问题是: ...
- FOFA 批量采集url 图形化界面编写
这是脚本 # coding:utf- import requests,re import time import sys import getopt import base64 guizhe='' s ...
- elasticsearch java索引的增删改查
1.创建索引并插入数据 Map<String, Object> json = new HashMap<String, Object>(); json.put("use ...
- Qt编写数据可视化大屏界面电子看板12-数据库采集
一.前言 数据采集是整个数据可视化大屏界面电子看板系统核心功能,没有数据源,这仅仅是个玩具UI,没啥用,当然默认做了定时器模拟数据,产生随机数据,这个可以直接配置文件修改来选择采用何种数据采集方法,总 ...
- linux简单命令3---帮助命令
1:帮助命令:man 命令: 2:这个帮助用的比较多(还是中文):命令 --help 3:shell帮助 4:详细命令(比man更详细)帮助,用的少,比较麻烦:info
- PowerDesigner常用命令
在Tools=>Execute Commands下的Edit/Run Scripts,或者通过Ctrl+Shift+X就可以运行脚本.如图: 1.将所有的表名和列名都修改为大写 '******* ...
- phpcms后台添加会员报v9_sso_member表缺失
坑货..表前缀设置 两个地方都有 一个是默认的caches/configs/目录 还有个是phpsso_server/caches/configs/ 如果改了表前缀 这两个地方的database都要改 ...