1050. String Subtraction (20)
this problem is from PAT, which website is http://pat.zju.edu.cn/contests/pat-a-practise/1050.
firstly i think i can use double circulation to solve it ,however the result of two examples is
proofed to be running time out. So as the problem said, it is not that simple to make it fast.
then i search the problem , there are many people using the search table. i think it is a very
good idea. so i changed the algorithm.
#include<iostream>
#include<string>
#include<vector>
using namespace std; int MAX=; int main()
{
string s1,s2;
getline(cin,s1);
getline(cin,s2);
vector<bool> isExisted(MAX,false);
for (int i = ; i < s2.size(); i++)
{
isExisted[s2[i]] = true;
}
for (int i = ; i < s1.size(); i++)
{
if (!isExisted[s1[i]]) cout<<s1[i];
}
cout<<endl;
}
so this time the Time complexity is O(n) ,which is much faster than the previous one.
1050. String Subtraction (20)的更多相关文章
- PAT 解题报告 1050. String Subtraction (20)
1050. String Subtraction (20) Given two strings S1 and S2, S = S1 - S2 is defined to be the remainin ...
- 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 Level) 1050. String Subtraction (20)
简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...
- 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 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 ...
- 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 ...
随机推荐
- MATLAB常用数据类型的转换
一直以来,在使用MATLAB进行运算的过程中,经常会用到对图像的各种处理,因此需要对图像进行数据转换,因此对经常用到的转换进行整理,方便查看. 1.uint8转化为double用来方便图像的运算: d ...
- subclipse svn 在64位win7下报Failed to load JavaHL Library
- linux下简单文本处理
1. 根据第二列的数据来确定第一列的值 awk '{if(a!=$0)i++;print i,$0;a=$0}' arr >arr.out 2. 补齐长度 seq arr.out|awk '{p ...
- ThinkPHP中U方法与url的四种访问模式
ThinkPHP中U方法的用处主要是完成对url地址的组装,在模板中使用U方法而不是固定写死URL地址的好处在于,一旦你的环境变化或者参数设置改变,你不需要更改模板中的任何代码.在模板中的调用格式需 ...
- C++ 我想这样用(七)
话接前篇,继续基于对象编程语法的剩余部分: 6.类的const成员函数和const对象 const数据成员:跟const常量一样,只是一个在类里(而且是在构造函数里),一个在类外而已,都必须初始化. ...
- 使用Ant发布hadoop代码到服务器
首先,搭建Ant环境: 1.1.下载antzip包,可以直接从官网下,也可以从我的csdn账号下载,这里我使用的Ant版本是:apache-ant-1.8.4-bin CSDN Ant 所需jar包下 ...
- python编码问题的理解与解决
错误:'ascii' codec can't encode characters in position 0-1: ordinal not in range(128) 看到网上很多都不清楚,做了一天的 ...
- NSLog说明
%@ 对象 %d,%i 整型 (%i的老写法) %hd 短整型 %ld , %lld 长整型 %u 无符整型 %f 浮点型和double型 %0.2f 精度浮点数,只保留两位小数 %x,%X 二进制整 ...
- Oracle的回收站和闪回查询机制(一)
实际工作中,我们经常会遇到一些情况,误删除某些表或某些表的某些记录,这时候就需要我们将这些记录重新插入进去.如何才能解决这个问题呢? Oracle的Flashback query(闪回查询)为我们解决 ...
- 嵌入式LINUX入门到实践(一)
MINI2440 IIC协议 IIC协议在工程中应用广泛,在我看来,此协议的优势就在于其硬件及其简单,结构清晰. 首先来解读一下S3C2440A这款芯片的IIC协议. 一.一个协议的解读从如上结构图中 ...