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)的更多相关文章

  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 ...

  2. PAT 甲级 1050 String Subtraction (20 分) (简单送分,getline(cin,s)的使用)

    1050 String Subtraction (20 分)   Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be t ...

  3. PAT (Advanced Level) 1050. String Subtraction (20)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  4. PAT甲题题解-1050. String Subtraction (20)-水题

    #include <iostream> #include <cstdio> #include <string.h> #include <algorithm&g ...

  5. PAT Advanced 1050 String Subtraction (20 分)

    Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking ...

  6. 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 ...

  7. 1050 String Subtraction (20分)

    Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking ...

  8. PAT练习--1050 String Subtraction (20 分)

    题⽬⼤意:给出两个字符串,在第⼀个字符串中删除第⼆个字符串中出现过的所有字符并输出. 这道题的思路:将哈希表里关于字符串s2的所有字符都置为true,再对s1的每个字符进行判断,若Hash[s1[i] ...

  9. 【PAT甲级】1050 String Subtraction (20 分)

    题意: 输入两个串,长度小于10000,输出第一个串去掉第二个串含有的字符的余串. trick: ascii码为0的是NULL,减去'0','a','A',均会导致可能减成负数. AAAAAccept ...

随机推荐

  1. 第二百七十九天 how can I 坚持

    竟然说我是猪,也是有点受不了了.其实也没什么,无所谓. 一个人有了信仰,不管成不成功,至少不会迷茫. sql语句,left  on  and  和where,left on是先检索,再关联,主表是完整 ...

  2. 【转】Nginx系列(三)--管理进程、多工作进程设计

    原博文出于:http://blog.csdn.net/liutengteng130/article/details/46700999  感谢! Nginx由一个master进程和多个worker进程组 ...

  3. JavaScript如何判断参数为浮点型

    在codewars里,确实可以学到很多很酷的方法,例如这一次的题目是判断数字是否为浮点型.我一开始是想有没有原生的js方法,像isNaN(),isFinite(),在前者Infinity是不属于NaN ...

  4. HDU 5792 World is Exploding (树状数组)

    World is Exploding 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5792 Description Given a sequence ...

  5. Test Spring el with ExpressionParser

    Spring expression language (SpEL) supports many functionality, and you can test those expression fea ...

  6. threading模块

    threading — Higher-level threading interface¶ Source code: Lib/threading.py This module constructs h ...

  7. CSS 酷站

    http://mikkelbang.com/#!videos

  8. Chapter 8. Classes

    8.1. Class Declarations 8.1.1. Class Modifiers 8.1.1.1. abstract Classes 8.1.1.2. final Classes 8.1. ...

  9. ID生成器的一种可扩展实现方案

    ID生成器主要为了解决业务程序生成记录ID的场景,而一个好的ID生成器肯定要满足扩展性好.并发性好的特点,本文下面介绍一种满足上述特点的实现方案. 此方案的核心思想是:每次需要扩容机器时,将每个节点维 ...

  10. socket断开连接的四次握手及常见过程解析

    TCP的协议文档对TCP的一些规定:文档名称-RFC793  TCP消息头的控制位 URG:紧急指针字段有效 ACK:确认头部字段有效 PSH:强制函数 RST:重置链接 SYN:同步系列号码 FIN ...