PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
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 1. 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.
题意:
很简单的一道题目,除去第一个字符串中含有的第二个字符串的字符即可
AC代码:
- #include<iostream>
- #include<algorithm>
- #include<vector>
- #include<queue>
- #include<map>
- #include<string>
- #include<cstring>
- using namespace std;
- string s1;
- string s2;
- int a[];//标准ascii码字符集共有128个编码
- int main(){
- getline(cin,s1);
- getline(cin,s2);
- memset(a,,sizeof(a));
- int l1,l2;
- l1=s1.size();
- l2=s2.size();
- for(int i=;i<l2;i++){
- a[s2[i]]=;
- }
- for(int i=;i<l1;i++){
- if(a[s1[i]]==) continue;
- cout<<s1[i];
- }
- return ;
- }
使用set
- #include<bits/stdc++.h>
- using namespace std;
- set<char>st;
- int main(){
- string s1,s2;
- getline(cin,s1);
- getline(cin,s2);
- for(int i=;i<s2.size();i++)
- st.insert(s2[i]);
- for(int i=;i<s1.size();i++){
- if(st.find(s1[i])==st.end())
- cout<<s1[i];
- }
- return ;
- }
PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)的更多相关文章
- PAT甲级——1050 String Subtraction
1050 String Subtraction Given two strings S1 and S2, S=S1−S2 is defined to be the remain ...
- PAT Advanced 1050 String Subtraction (20 分)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
- PAT练习--1050 String Subtraction (20 分)
题⽬⼤意:给出两个字符串,在第⼀个字符串中删除第⼆个字符串中出现过的所有字符并输出. 这道题的思路:将哈希表里关于字符串s2的所有字符都置为true,再对s1的每个字符进行判断,若Hash[s1[i] ...
- PAT Advanced 1050 String Subtraction (20) [Hash散列]
题目 Given two strings S1 and S2, S = S1 – S2 is defined to be the remaining string afer taking all th ...
- PAT 甲级 1050 String Subtraction
https://pintia.cn/problem-sets/994805342720868352/problems/994805429018673152 Given two strings S~1~ ...
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- 1050 String Subtraction (20分)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
- 1050. String Subtraction (20)
this problem is from PAT, which website is http://pat.zju.edu.cn/contests/pat-a-practise/1050. firs ...
- PAT甲级——A1050 String Subtraction
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
随机推荐
- PWA相关代码
sw.js 文件 let CacheName = 'plus-v1'; var filesToCache = [ ]; self.addEventListener('install', functio ...
- 云计算(5)---MapReduce
什么是MapReduce 例如用MapReduce如何计算12+22+32+42 用MapReduce执行Wordcount 步骤1:Map map task1 和map task2是独立,并行进行 ...
- seaborn模块的基本使用
Seaborn是基于matplotlib的Python可视化库. 它提供了一个高级界面来绘制有吸引力的统计图形.Seaborn其实是在matplotlib的基础上进行了更高级的API封装,从而使得作图 ...
- Spring MVC 学习笔记(一)
• 1.SpringMVC概述 • 2.SpringMVC的HelloWorld • 3.使用@RequestMapping映射请求 • 4.映射请求参数&请求头 • 5.处理模型数据 • 6 ...
- Luogu 4751 动态DP 模板
题面 动态求最大独立集 题解 树剖后用矩阵转移. 具体见Tweetuzki的洛谷博客 CODE #include <bits/stdc++.h> using namespace std; ...
- HDU-1465-不容易系列之一(容斥)
链接: https://vjudge.net/problem/HDU-1465 题意: 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好"一件"事情尚且不易 ...
- 30、[源码]-AOP原理-注册AnnotationAwareAspectJAutoProxyCreavi
30.[源码]-AOP原理-注册AnnotationAwareAspectJAutoProxyCreavi
- sql server 将某一列的值拼成一个字符串 赋值到一个字段内
DECLARE @refCodeitems VARCHAR(800), SELECT @refCodeitems=ISNULL(@refCodeitems,'')+refCodeitem +'/' ...
- 解决ubuntu14.04 启动时卡在 Waiting for network configuration...
两种解决方法: 1.把/etc/network/interfaces中没有用到的配置删除掉 2.把 /etc/init/failsafe.conf 文件中的 sleep 40, sleep 59 注释 ...
- 【SPOJ】Longest Common Substring II
[SPOJ]Longest Common Substring II 多个字符串求最长公共子串 还是将一个子串建SAM,其他字符串全部跑一边,记录每个点的最大贡献 由于是所有串,要对每个点每个字符串跑完 ...