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 ...
 
随机推荐
- 几种常见的FTP软件的二进制设置说明
			
几种常见的FTP软件的二进制设置说明: 1.FlashFXP: 打开 FlashFXP:在工具栏中,选项 => 参数(也可以直接按F6键),在弹出来的窗口中,选择“传输(T)”卡,在传输模式中选 ...
 - Text Kit入门
			
更详细的内容可以参考官方文档 <Text Programming Guide for iOS>. “Text Kit指的是UIKit框架中用于提供高质量排版服务的一些类和协议,它让程序能够 ...
 - wuzhicms内的全局函数--load_class()
			
load_class() 可以加载并实例化/coreframe/app/模块名/libs/class/$class.class.php类文件里的对象,如果有扩展类文件EXT_$class.class. ...
 - 多校7 HDU5816 Hearthstone 状压DP+全排列
			
多校7 HDU5816 Hearthstone 状压DP+全排列 题意:boss的PH为p,n张A牌,m张B牌.抽取一张牌,能胜利的概率是多少? 如果抽到的是A牌,当剩余牌的数目不少于2张,再从剩余牌 ...
 - (转载)OC学习篇之---类的定义
			
之前已经介绍了OC中的一个程序HelloWorld,今天我们继续学习OC中类的相关知识. OC和C的最大区别就是具有了面向对象的功能,那么说到面向对象,就不得不说类这个概念了,如果学过Java的话,那 ...
 - ArrayList、LinkedList、HashMap的遍历及遍历过程中增、删元素
			
ArrayList.LinkedList.HashMap是Java中常用到的几种集合类型,遍历它们是时常遇到的情况.当然还有一些变态的时候,那就是在遍历的过程中动态增加或者删除其中的元素. 下面的例子 ...
 - Chapter 1 初探Caffe
			
首先下载windows下源码: Microsoft 官方:GitHub - Microsoft/caffe: Caffe on both Linux and Windows 官方源码使用Visual ...
 - 第二百九十五天 how can i 坚持
			
买了个小米电话卡,写的让周六日送,非得今天给送来,浪费了1块钱.买回来还没法激活,这.. 昨天差点挂掉,今天感觉好多了,不过今天好冷,回来快冻死了. 今天啊,年终奖订下来了,没有想象的高 啊,有点小失 ...
 - Windows下cmd的替代软件——PowerCmd
			
Powercmd 是一款运行在windows下的cmd增强软件(A Better Command Prompt Replacement Tool),当前最新的版本为2.2. 官方提供试用版,貌似没有功 ...
 - BAT-使用BAT方法结束进程(删除进程)
			
@echo off taskkill /f /im GAM.exe taskkill /f /im GCL10.exe