PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking all the characters in S2 from S1. Your task is simply to calculate S1−S2 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 S1 and S2, 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 S1−S2 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)的使用)的更多相关文章
- PAT甲级——1050 String Subtraction
1050 String Subtraction Given two strings S1 and S2, S=S1−S2 is defined to be the remain ...
- PAT Advanced 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 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 ...
- PAT 甲级 1050 String Subtraction
https://pintia.cn/problem-sets/994805342720868352/problems/994805429018673152 Given two strings S~1~ ...
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- 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)
this problem is from PAT, which website is http://pat.zju.edu.cn/contests/pat-a-practise/1050. firs ...
- PAT甲级——A1050 String Subtraction
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
随机推荐
- 前端学习笔记--CSS入门
1.css概述: 2.css语法: 3.css添加方法: 用单独的文件存储css样式的优点: 优先级: h3得到的样式是内嵌样式覆盖了外部样式. 4.css选择器 标签选择器: 类别选择器: ID选择 ...
- MyCat(1.1)Mycat基本介绍
[1]学习目的 (1)掌握在数据库负载增大时的处理方法 (2)理解mycat的基础概念 (3)掌握mycat基础配置和监控方法 [2]Mycat的前世今生 官网:http://mycat.io/ 下载 ...
- 带有EXE参数的启动
(一).先制作一个带启动参数的EXE文件. 步骤: 1.定义全局私有变量:private string[] s = new string[1]; //这里为了简单起见,只做一个 ...
- 判断字符串是否是IP地址
#include <stdio.h>#include <string.h> bool isIP(const char* str); int main(){ char str[] ...
- bootstrap之collapse
<div class="container"> <!--该button可以控制div是否显示 1.首先给button设置data-toggle="col ...
- [USACO08FEB]酒店Hotel 线段树
[USACO08FEB]酒店Hotel 线段树 题面 其实就是区间多维护一个lmax,rmax(表示从左开始有连续lmax个空房,一直有连续rmax个空房到最右边),合并时讨论一下即可. void p ...
- (5)打鸡儿教你Vue.js
条件与循环 条件判断使用 v-if 指令 <p v-if="seen"> <template v-if="ok"> <script ...
- (转)hadoop 配置文件解释
借鉴:https://blog.csdn.net/wangming520liwei/article/details/78923216 Hadoop 参数配置 详解 一.常用端口 组件 节点 默认端口 ...
- 获取Linux系统运行时间
uptime |sed 's/^.*up//' |sed 's/users.*//g'|awk '{for(i=1;i<NF;++i) printf $i "\t";prin ...
- [WEB安全]Dirsearch工具命令
下载项目,并打开 ┌─[root@kali]─[/kali] └──╼ #git clone https://github.com/maurosoria/dirsearch ┌─[root@kali] ...