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:

  1. They are students.
  2. aeiou

Sample Output:

  1. Thy r stdnts.

题意:

很简单的一道题目,除去第一个字符串中含有的第二个字符串的字符即可

AC代码:

  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<queue>
  5. #include<map>
  6. #include<string>
  7. #include<cstring>
  8. using namespace std;
  9. string s1;
  10. string s2;
  11. int a[];//标准ascii码字符集共有128个编码
  12. int main(){
  13. getline(cin,s1);
  14. getline(cin,s2);
  15. memset(a,,sizeof(a));
  16. int l1,l2;
  17. l1=s1.size();
  18. l2=s2.size();
  19. for(int i=;i<l2;i++){
  20. a[s2[i]]=;
  21. }
  22. for(int i=;i<l1;i++){
  23. if(a[s1[i]]==) continue;
  24. cout<<s1[i];
  25. }
  26. return ;
  27. }

使用set

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. set<char>st;
  4. int main(){
  5. string s1,s2;
  6. getline(cin,s1);
  7. getline(cin,s2);
  8. for(int i=;i<s2.size();i++)
  9. st.insert(s2[i]);
  10. for(int i=;i<s1.size();i++){
  11. if(st.find(s1[i])==st.end())
  12. cout<<s1[i];
  13. }
  14. return ;
  15. }

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. PWA相关代码

    sw.js 文件 let CacheName = 'plus-v1'; var filesToCache = [ ]; self.addEventListener('install', functio ...

  2. 云计算(5)---MapReduce

    什么是MapReduce 例如用MapReduce如何计算12+22+32+42 用MapReduce执行Wordcount 步骤1:Map map task1 和map task2是独立,并行进行 ...

  3. seaborn模块的基本使用

    Seaborn是基于matplotlib的Python可视化库. 它提供了一个高级界面来绘制有吸引力的统计图形.Seaborn其实是在matplotlib的基础上进行了更高级的API封装,从而使得作图 ...

  4. Spring MVC 学习笔记(一)

    • 1.SpringMVC概述 • 2.SpringMVC的HelloWorld • 3.使用@RequestMapping映射请求 • 4.映射请求参数&请求头 • 5.处理模型数据 • 6 ...

  5. Luogu 4751 动态DP 模板

    题面 动态求最大独立集 题解 树剖后用矩阵转移. 具体见Tweetuzki的洛谷博客 CODE #include <bits/stdc++.h> using namespace std; ...

  6. HDU-1465-不容易系列之一(容斥)

    链接: https://vjudge.net/problem/HDU-1465 题意: 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好"一件"事情尚且不易 ...

  7. 30、[源码]-AOP原理-注册AnnotationAwareAspectJAutoProxyCreavi

    30.[源码]-AOP原理-注册AnnotationAwareAspectJAutoProxyCreavi

  8. sql server 将某一列的值拼成一个字符串 赋值到一个字段内

    DECLARE @refCodeitems VARCHAR(800),   SELECT @refCodeitems=ISNULL(@refCodeitems,'')+refCodeitem +'/' ...

  9. 解决ubuntu14.04 启动时卡在 Waiting for network configuration...

    两种解决方法: 1.把/etc/network/interfaces中没有用到的配置删除掉 2.把 /etc/init/failsafe.conf 文件中的 sleep 40, sleep 59 注释 ...

  10. 【SPOJ】Longest Common Substring II

    [SPOJ]Longest Common Substring II 多个字符串求最长公共子串 还是将一个子串建SAM,其他字符串全部跑一边,记录每个点的最大贡献 由于是所有串,要对每个点每个字符串跑完 ...