题目描述
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 - S2for any given strings. However, it might not be that simple to do it fast.
输入
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.
输出
For each test case, print S1 - S2 in one line.
样例输入 复制
They are students.
aeiou
样例输出 复制
Thy r stdnts.
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
#define MAX 10010
#define MAX_ASCII 260
int main()
{
//使用散列函数,先遍s2中的字符,再遍历s1,有s2中的元素就删除,否则就输出
char s1[MAX],s2[MAX];
int hash[MAX_ASCII]={0};//字符最多就 理论上256
while(fgets(s1,sizeof(s1),stdin))
{
fgets(s2,sizeof(s2),stdin);
char *p=s2;
while(*p)//;利用指针遍历s2
{
hash[*p]=1;//将出现过的字符值值至为1
++p;
}
p=s1;
while(*p)
{
if(!hash[*p])//没出现过就打印
putchar(*p);
++p;
}
putchar('\n');
}
return 0;
}