A1050 String Subtraction (20 分)
一、技术总结
- 这个是使用了一个bool类型的数组来判断该字符是否应该被输出。
- 然后就是如果在str2中出现那么就判断为false,被消除不被输出。
- 遍历str1如果字符位true则输出该字符。
- 还有需要注意的是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 分)的更多相关文章
- PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
1050 String Subtraction (20 分) Given two strings S1 and S2, S=S1−S2 is defined to be t ...
- PAT Advanced 1050 String Subtraction (20 分)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
- 1050 String Subtraction (20分)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
- PAT练习--1050 String Subtraction (20 分)
题⽬⼤意:给出两个字符串,在第⼀个字符串中删除第⼆个字符串中出现过的所有字符并输出. 这道题的思路:将哈希表里关于字符串s2的所有字符都置为true,再对s1的每个字符进行判断,若Hash[s1[i] ...
- 【PAT甲级】1050 String Subtraction (20 分)
题意: 输入两个串,长度小于10000,输出第一个串去掉第二个串含有的字符的余串. trick: ascii码为0的是NULL,减去'0','a','A',均会导致可能减成负数. AAAAAccept ...
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- pat1050. String Subtraction (20)
1050. String Subtraction (20) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Giv ...
- 1050. String Subtraction (20)
this problem is from PAT, which website is http://pat.zju.edu.cn/contests/pat-a-practise/1050. firs ...
- PAT---1050. String Subtraction (20)
#include<iostream> #include<string.h> #include<stdio.h> using namespace std; #defi ...
随机推荐
- Ubuntu 16.04上anaconda安装和使用教程,安装jupyter扩展等 | anaconda tutorial on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/23014ca5/,欢迎阅读最新内容! anaconda tutorial on ubuntu 16.04 Guide versio ...
- redis命令之 ----String(字符串)
SET SET key value [EX seconds] [PX milliseconds] [NX|XX] 将字符串值 value 关联到 key . 如果 key 已经持有其他值, SET 就 ...
- CodeForce 176C Playing with Superglue
Two players play a game. The game is played on a rectangular board with n × m squares. At the beginn ...
- LeetCode 1293. Shortest Path in a Grid with Obstacles Elimination
题目 非常简单的BFS 暴搜 struct Node { int x; int y; int k; int ans; Node(){} Node(int x,int y,int k,int ans) ...
- Linux(CentOS)启动时自动执行脚本(rc.local)
下面说说通过rc.local文件进行开机启动 1.首先创建一个启动脚本,这里以启动docker为例 创建 docker-startup.sh 脚本 #! /bin/bash /usr/bin/mk-d ...
- DevExpress的图形按钮菜单栏控件WindowsUIButtonPanel的布局、使用和设置按钮的点击事件
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...
- js函数定义及一些说明
1.javascript定义函数的三种方法一.function语句//这个方法比较常用function fn(){ alert("这是使用function语句进行函数定义");}f ...
- js数组试列题
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Codeforces 939A题,B题(水题)
题目链接:http://codeforces.com/problemset/problem/939/A A题 A. Love Triangle time limit per test 1 second ...
- linux源代码获取
Ubuntu获取 # which ls /bin/ls # dpkg -S /bin/ls coreutils: /bin/ls # apt-get source coreutils CentOS获取 ...