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 ...
随机推荐
- jquery动态加载问题
对于append的元素,原有的方法不生效 解决:用on方法 找到的:http://www.zhidao91.com/jquery-html-live-on/ 解决使用jQuery采用append添加的 ...
- Memcached原理深度分析详解
Memcached是 danga.com(运营LiveJournal的技术团队)开发的一套分布式内存对象缓存系统,用于在动态系统中减少数据库负载,提升性能.关于这个东 西,相信很多人都用过,本文意在通 ...
- JAVA中的throws和throw的区别
Java 一直对java中的throws和throw不太理解.最近一直在查这两个方面的资料,算是能明白一点吧.如果我下面的观点哪有不对,希望指出来,我加以改进. throw:( ...
- 【转】Unity3D中脚本的执行顺序和编译顺序(vs工程引用关系)
http://www.cnblogs.com/champ/p/execorder.html 在Unity中可以同时创建很多脚本,并且可以分别绑定到不同的游戏对象上,它们各自都在自己的生命周期中运行.与 ...
- 捕获JS 错误日志
最近在做项目的过程中,发现很多JS报错没有引起重视,我就想想把JS错误捕获了,然后展示在我们一个平台上 具体实现代码: window.onerror = function(message, url, ...
- Redis学习一 五种基本的数据类型
首先一定要确保Redis是运行这的. 不知道为啥,我的电脑陪完服务以后,刚配完的时候好使,已重启就不行了,死活起不来. 好吧,这些暂时不是很重要. 运行 redis-server.exe 在开一个窗口 ...
- eclipse如何修改dynamic web module version
eclipse如何修改dynamic web module version 一.修改工程属性: 右键eclipse的工程,选择属性,再选择Project Facets里面中选择Dynamic Web ...
- 转:自定义ASP.NET MVC Html辅助方法
在ASP.NET MVC中,Html辅助方法给我们程序员带来很多方便,其重要性也就不言自明.有时候,我们不想重复地写一些HTML代码,或者MS没有提供我们想要的那个HTML标签的Html辅助方法,那么 ...
- 返回键 隐藏、、收起键盘textView|textField
/** 隐藏 返回键 的做法,将title置为空 */ self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWith ...
- shell 使用for循环 启动后台任务
为了统计多天的数据并按照天为文件名输出,写了脚本,脚本可以统计单天的数据.为了实现多天的同时进行采用 启动多个进程后台执行形式: 但是直接 执行的参数后面加上& 并不能解决,采用 echo & ...