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. jquery基础知识2

    1.js和jquery对象的转换 js==>jquery对象 $(js对象) jquery==>js jq对象[index] jq对象.get(index) <!DOCTYPE ht ...

  2. P2P system: Introduction

    P2P system : peer-to-peer system 一些流行的P2P system: Napster, Gnutella 我们为什么研究P2P system 大型的分布式系统有成千上万个 ...

  3. 文件读写(三)利用FileStream类操作字节数组byte[]、BinaryFormatter、内存流MemoryStream

    一.Stream类概述 在.NET Framework中,文件和流是有区别的.文件是存储在磁盘上的数据集,它具有名称和相应的路径.当打开一个文件并对其进行读/写时,该文件就称为流(stream).但是 ...

  4. singleton单例模式小结

    1.饿汉模式 public class SingletonEntity2 { // 在类加载的时候创建对象:饿汉模式 public static SingletonEntity2 obj = new ...

  5. 多继承以及MRO顺序

    class A: def test(self): print("A --- test方法") def demo(self): print("A --- demo方法&qu ...

  6. SQlAlchemy的增删改查

    一.创建数据表 # ORM中的数据表是什么呢? # Object Relation Mapping # Object - Table 通过 Object 去操纵数据表 # 从而引出了我们的第一步创建数 ...

  7. for循环中使用async/await

    async function printFiles () { const files = await getFilePaths(); await Promise.all(files.map(async ...

  8. scoket --- 练习

    三次握手,四次挥手(面试会问) 三次握手建连 [] 最开始的时候客户端和服务器都是处于CLOSED状态.主动打开连接的为客户端,被动打开连接的是服务器. TCP服务器进程先创建传输控制块TCB,时刻准 ...

  9. php面向对象:类的继承实例讲解

    什么是类的继承?说白了,我觉得就是提高代码使用效率的.下面我就给大家介绍下继承.大理石平台维修 类的继承概念 子类继承父类的所有成员变量个方法,包括构造方法,当子类被实例化时,php会现在子类中查询构 ...

  10. vue报错 :NavigationDuplicated {_name: "NavigationDuplicated", name: "NavigationDuplicated"}

    解决的几种办法 https://blog.csdn.net/weixin_43202608/article/details/98884620 这个适合所有vue的UI框架 在main.js下添加一下代 ...