PAT1050. String Subtraction

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.
思路:提示时间短的话一定要记住哈希,哈希就是用空间换时间。

 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4
 5 bool Harsh[128]={
 6     false
 7 };
 8 #define MAX 10010
 9 char str1[MAX];
10 char str2[MAX];
11 int main(int argc, char *argv[])
12 {
13     gets(str1);
14     int i=0;
15     for(char ch=getchar();ch!=‘\n‘;ch=getchar())
16     {
17         Harsh[ch]=true;
18         str2[i++]=ch;
19     }
20     for(int i=0;str1[i]!=‘\0‘;i++)
21     {
22         if(!Harsh[str1[i]])
23            putchar(str1[i]);
24     }
25     putchar(‘\n‘);
26     return 0;
27 }

时间: 2024-10-16 05:29:44

PAT1050. String Subtraction的相关文章

PAT---1050. String Subtraction (20)

#include<iostream> #include<string.h> #include<stdio.h> using namespace std; #define N 128 int main() { int i=0,sum; bool is_exist[N]; char ch; char str[10000]; //void *memset(void *s,int ch,size_t n) //将s所指向的某一块内存中的前n个字节的内容全部设置为ch指定的ASC

1050. String Subtraction (20)【字符串处理】——PAT (Advanced Level) Practise

题目信息 1050. String Subtraction (20) 时间限制10 ms 内存限制65536 kB 代码长度限制16000 B 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 giv

1050. String Subtraction

1050. String Subtraction (20) 时间限制 10 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue 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 calc

pat 1050 String Subtraction(20 分)

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 all the characters in S?2?? from S?1??. Your task is simply to calculate S?1???S?2?? for any given strings. However, it

1050 String Subtraction (20 分)哈希 map

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 all the characters in S?2?? from S?1??. Your task is simply to calculate S?1???S?2?? for any given strings. However, it

1050 String Subtraction (20 分)

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 all the characters in S?2??from S?1??. Your task is simply to calculate S?1??−S?2?? for any given strings. However, it

PAT:1050. String Subtraction (20) AC

#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; bool HARSH[260]; //实际上申请来之后初试都是false int main() { fill(HARSH,HARSH+260,true); char str1[10066]; char str2[10066]; gets(str1); gets(str2); int len1=strlen(str1)

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 Sp

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

简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<vector> using namespace std; const int maxn=100000