1050 String Subtraction (20 分)
 

Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking all the characters in S​2​​ from S​1​​. Your task is simply to calculate S​1​​−S​2​​ 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 S​1​​ and S​2​​, 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 S​1​​−S​2​​ 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)的使用)的更多相关文章

  1. PAT甲级——1050 String Subtraction

    1050 String Subtraction Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remain ...

  2. PAT Advanced 1050 String Subtraction (20 分)

    Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking ...

  3. PAT练习--1050 String Subtraction (20 分)

    题⽬⼤意:给出两个字符串,在第⼀个字符串中删除第⼆个字符串中出现过的所有字符并输出. 这道题的思路:将哈希表里关于字符串s2的所有字符都置为true,再对s1的每个字符进行判断,若Hash[s1[i] ...

  4. 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 ...

  5. PAT 甲级 1050 String Subtraction

    https://pintia.cn/problem-sets/994805342720868352/problems/994805429018673152 Given two strings S~1~ ...

  6. PAT 解题报告 1050. String Subtraction (20)

    1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...

  7. 1050 String Subtraction (20分)

    Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking ...

  8. 1050. String Subtraction (20)

    this problem  is from PAT, which website is http://pat.zju.edu.cn/contests/pat-a-practise/1050. firs ...

  9. PAT甲级——A1050 String Subtraction

    Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking ...

随机推荐

  1. cookie、session与用户认证组件

    1.cookie def login(request): if request.method == "GET": return render(request,"login ...

  2. go mod使用

    GO111MODULE 有三个值:off, on和auto(默认值) GO111MODULE=off,go命令行将不会支持module功能,寻找依赖包的方式将会沿用旧版本那种通过vendor目录或者G ...

  3. SpringBoot项目启动报错:java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

    .   ____          _            __ _ _ /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \( ( )\___ | '_ | '_| | ...

  4. 编写一个求圆面积的C语言程序

    #include<stdio.h>   //文件包含//#define PI 3.14     //宏定义//void main()         { float r,s; scanf( ...

  5. 第四章 初始CSS

    一.引入样式 1.行内样式表 <h1 style="color: red;font-size: 18px;">10-30</h1> 2.内部样式表(在hea ...

  6. 原生JS实现购物车全选多选按钮功能

    对于JS初学者来说,一个完整的购物车实现还是挺难的,逻辑功能挺多.写出完整功能,能提升不少JS基础,下面实现购物车全选多选按钮功能: 首先HTML及CSS部分: <style> table ...

  7. 【解题报告】CSP2019-S D1T1 格雷码

    题目链接:https://www.luogu.org/problem/P5657 话说这道题怎么是道橙题啊. 基本思路 因为n位格雷码的前2n-1位就是n-1位格雷码前面加了一位‘0’,所以可以把它们 ...

  8. hbase的region

    一.Region 概念 Region是表获取和分布的基本元素,由每个列族的一个Store组成.对象层级图如下: Table (HBase table) Region (Regions for the ...

  9. Spring的注解@Qualifier用法

    Spring的注解@Qualifier用法在Controller中需要注入service那么我的这个server有两个实现类如何区分开这两个impl呢?根据注入资源的注解不同实现的方式有一点小小的区别 ...

  10. soap1.1与soap1.2

    1.soap1.2 如果加上jar包后,项目启动报错,有可能是jar包没起作用, 解决方法:把jar包移除,重新加入jar包 TCP/IP Monitor监测到的内容: soap1.2请求与soap1 ...