一、技术总结

  1. 这个是使用了一个bool类型的数组来判断该字符是否应该被输出。
  2. 然后就是如果在str2中出现那么就判断为false,被消除不被输出。
  3. 遍历str1如果字符位true则输出该字符。
  4. 还有需要注意的是memset函数是在头文件#include"cstring"中。

二、参考代码:

#include<iostream>
#include<cstring>
using namespace std;
bool hashTable[256];
int main(){
memset(hashTable,false,sizeof(hashTable));
string str1,str2;
getline(cin,str1);
getline(cin,str2);
int len1 = str1.length();
int len2 = str2.length();
for(int i = 0; i < len1; i++){
hashTable[str1[i]] = true;
}
for(int i = 0; i < len2; i++){
hashTable[str2[i]] = false;
}
for(int i = 0; i < len1; i++){
if(hashTable[str1[i]] == true){
cout << str1[i];
}
}
return 0;
}

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

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

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

  5. 【PAT甲级】1050 String Subtraction (20 分)

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

  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. pat1050. String Subtraction (20)

    1050. String Subtraction (20) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Giv ...

  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---1050. String Subtraction (20)

    #include<iostream> #include<string.h> #include<stdio.h> using namespace std; #defi ...

随机推荐

  1. telnet: Unable to connect to remote host: No route to host

    用iptables -F这个命令来关闭防火墙,但是使用这个命令前,千万记得用iptables -L查看一下你的系统中所有链的默认target,iptables -F这个命令只是清除所有规则,只不会真正 ...

  2. LeetCode 841:钥匙和房间 Keys and Rooms

    题目: ​ 有 N 个房间,开始时你位于 0 号房间.每个房间有不同的号码:0,1,2,...,N-1,并且房间里可能有一些钥匙能使你进入下一个房间. ​ 在形式上,对于每个房间 i 都有一个钥匙列表 ...

  3. Singnal R 练习参考

    项目地址:https://gitee.com/dhclly/IceDog.SignalR/tree/master/src/chat demo的实现均来自官方的教程,教程地址: ASP.NET Core ...

  4. 『珂朵莉树 Old Driver Tree』

    珂朵莉树 珂朵莉树其实不是树,只是一个借助平衡树实现的数据结构,主要是对于有区间赋值的数据结构题,可以用很暴力的代码很高效地完成任务,当然这是建立在数据随机的基础上的. 即使数据不是随机的,写一个珂朵 ...

  5. keepalived+Nginx实现主备保障Nginx的高可用。

    1.什么是keepalived? Keepalived是集群管理中保证集群高可用的一个服务软件,用来防止单点故障. Keepalived的作用是检测web服务器的状态,如果有一台web服务器死机,或工 ...

  6. Hashtable 负载因子Load Factor

    负载因子(load factor),它用来衡量哈希表的 空/满 程度,一定程度上也可以体现查询的效率,计算公式为: The ratio of the number of elements in the ...

  7. WPF 动态资源 DataContext="{DynamicResource studentListKey}" DisplayMemberPath="Name"

    public class StudentList:ObservableCollection<Student> { public List<Student> studentLis ...

  8. Activex在没有电子秤api的情况下获取串口数据

    大二做B/S架构的项目使用了安衡电子秤CHS-D+R和一款扫码枪,两个设备的串口使用一样,这款电子秤是相当的坑,没有开发的api,无奈只能自己开发Activex了,在B/S架构中进行引用Activex ...

  9. WebApi使用Unity实现IOC

    最近在学习ASP.NET MVC,使用Unity作为依赖注入容器.分别在WebAPI和MVC中使用.这篇文章介绍WebAPI,MVC的在下篇文章中介绍.下面是学习的一点经验. 一 IOC简单介绍 Io ...

  10. MySQL基础(二)(约束以及修改数据表)

    一,约束以及修改数据表 约束的作用?1.约束保证数据的完整性.一致性:2.约束分为表级约束.列级约束:3.约束类型包括:NOT NULL(非空约束).PRIMARY KEY(主键约束).UNIQUE ...