PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20)
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 104. 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.
题意
给定两个字符串,S1 和 S2,要求将 S2 中的字符从 S1 串中剔除。
分析
用 Hash 的方式标记需要剔除的字符。
#include <iostream>
#include <cstdio>
#include <string> using namespace std; int main()
{
int hs[] ={};
char cs[];
gets(cs);
string st = cs;
//getline(cin, st);
while () {
char c = getchar();
if (c == '\n') break;
hs[c] = ;
} for (int i=; i<st.size(); i++) {
if (hs[st[i]] == )
printf("%c", st[i]);
} return ;
}
PAT 解题报告 1050. String Subtraction (20)的更多相关文章
- PAT (Advanced Level) 1050. String Subtraction (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 【PAT甲级】1050 String Subtraction (20 分)
题意: 输入两个串,长度小于10000,输出第一个串去掉第二个串含有的字符的余串. trick: ascii码为0的是NULL,减去'0','a','A',均会导致可能减成负数. AAAAAccept ...
- 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) [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 (20)-水题
#include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...
- 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] ...
- 1050. String Subtraction (20)
this problem is from PAT, which website is http://pat.zju.edu.cn/contests/pat-a-practise/1050. firs ...
- 1050 String Subtraction (20分)
Given two strings S1 and S2, S=S1−S2 is defined to be the remaining string after taking ...
随机推荐
- Redis学习手册(Key操作命令)
一.概述: 在该系列的前几篇博客中,主要讲述的是与Redis数据类型相关的命令,如String.List.Set.Hashes和Sorted-Set.这些命 令都具有一个共同点,即所有的操作都是针对与 ...
- Centos 如何安装Django环境
Centos 如何安装Django环境 | 浏览:954 | 更新:2014-10-31 20:34 针对Centos这一Linux发行版,进行django环境的搭建过程介绍. 工具/原料 Cen ...
- 使用CodeIgniter框架搭建RESTful API服务
使用CodeIgniter框架搭建RESTful API服务 发表于 2014-07-12 | 分类于 翻译笔记 | 6条评论 在2011年8月的时候,我写了一篇博客<使用Cod ...
- Yii源码阅读笔记(二十)
View中应用布局和缓存内容部分: /** * Begins recording a block. * This method is a shortcut to beginning [[Block]] ...
- JAVA NIO的理解
在使用JAVA提供的Socket的IO方法时,服务端为了方便操作,会为每一个连接新建一个线程,一个线程处理一个客户端的数据交互.但是当大量客户端同服务端连接时,会创建大量的线程,线程之间的切换会严重影 ...
- wajueji
#include<stdio.h>int map[3]={42,3,99};int step[3]={0};int max=99999;void qian(){ int i=0; int ...
- java ReentrantReadWriteLock
// read and write lock is mutual exclusion lock //Listing 7-3. Using ReadWriteLock to Satisfy a Dict ...
- jquerymobile动态添加元素之后不能正确渲染解决方法
jquerymobile动态添加元素之后有些不能被正确渲染的解决方法: listview: 添加 jq(".detail").listview(&quo ...
- 大数据下的java client连接JDBC
1.前提 启动hiveserver2服务 url,username,password 2.程序 3.结果 emp的第一列与第二列
- SimpleUrlHandlerMapping 使用
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...