题⽬⼤意:给出两个字符串,在第⼀个字符串中删除第⼆个字符串中出现过的所有字符并输出。

这道题的思路:将哈希表里关于字符串s2的所有字符都置为true,再对s1的每个字符进行判断,若Hash[s1[i]]不为true,则输出。

代码如下:

#include<iostream>
#include<string>
using namespace std;
bool Hash[128] = {0};
int main(){
string s1, s2;
getline(cin, s1);
getline(cin, s2);
for(int i = 0; i < s2.length(); i++)
Hash[s2[i]] = true;
for(int i = 0; i < s1.length(); i++)
if(Hash[s1[i]] != true) cout << s1[i];
return 0;
}

(只有14行哈哈哈)

PAT练习--1050 String Subtraction (20 分)的更多相关文章

  1. PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  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 分)

    题意: 输入两个串,长度小于10000,输出第一个串去掉第二个串含有的字符的余串. trick: ascii码为0的是NULL,减去'0','a','A',均会导致可能减成负数. AAAAAccept ...

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

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

  8. PAT (Advanced Level) 1050. String Subtraction (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  9. PAT甲题题解-1050. String Subtraction (20)-水题

    #include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...

随机推荐

  1. node的内置常量 __dirname和 __filename

    node的内置常量 __ dirname和 __ filename __dirname当前文件(你用node运行的文件)所在的文件夹地址 // dirname.js console.log(__dir ...

  2. Http请求的Get和Post的区别?

    1. get从地址栏以明文的方式提交请求信息内容?username=admin&password=123,用户可见, 而post从请求正文提交请求信息内容,用户不可见. 2. get提交因为是 ...

  3. Mybatis Plus使用租户过滤无效解决方案

    异常内容: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.Pe ...

  4. python 基础数据类型汇总

    数据类型小结(各数据类型常用操作) 一.数字/整型int int()强行转化数字 二.bool类型False&True bool()强行转化布尔类型. 0,None,及各个空的字符类型为Fal ...

  5. Iterator 和 ListIterator 有什么区别?

    1.ListIterator 可以在遍历的时候,调用add()添加元素 2.ListIterator提供了更多的一些方法,如previous().hasPrevious() 等

  6. String工具类之“前缀比较”StringUtils.startsWith和StringUtils.startsWithIgnoreCase

    (1)字符串以prefix为前缀(区分大小写) StringUtils.startsWith(被比较的字符串,比较字符串) 总结: 根据下面代码发现,上面的例子有部分时错误的,有可能是因为思维原因,他 ...

  7. 顺利通过EMC实验(12)

  8. 13_奈奎斯特稳定性判据_Nyquist Stability Criterion_Part 1

    A曲线内有4个极点两个零点,则B曲线绕(0,0)逆时针两圈 A曲线是nyqyict contour中的曲线,P是A曲线内的()极点个数,Z是()极点个数,N是曲线B逆时针围绕(-1,0)的圈数 没过( ...

  9. 11_滞后补偿器_Lag Compensator_Matlab_Simulink

    下图中左边没有补偿器的稳态误差,右边是有只猴补偿器的稳态误差,H(s)为滞后补偿器的原因是H(s)bode图的相位图是负的 其中黄线是没有滞后补偿器的,蓝线是滞后补偿器中p = 1 ,q = 9的曲线 ...

  10. 关于CSS的个人理解

    CSS的个人理解 一.概念 层叠样式表,主要由属性和属性值(value)组成.(虽然HTML.CSS对代码大小写不敏感,但是属性和属性值对代码大小写是敏感的) 二.工作方式 1.工作原理 由浏览器将C ...