天天看點

Codeup哈希: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 - S2for any given strings. However, it might not be that simple to do it fast.

輸入

輸出

樣例輸入

They are students.
aeiou      

樣例輸出

Thy r stdnts.      
#include<bits/stdc++.h>
using namespace std;
const int MAX=150;//注意ASCII碼一共128個 ,需確定每一位字元都能被檢測 
const int MAXN=10005;
int main(){
	int hashTable[MAX]={0};
	string a,b;
	getline(cin,a);
	getline(cin,b);
	char ch[MAXN];
	int num=0;
	for(int i=0;i<b.length();i++){
			hashTable[b[i]]++;
	} 
	for(int i=0;i<a.length();i++){
		if(a[i]==' ') ch[num++]=a[i];//空格也需輸出
		else if(!hashTable[a[i]]){
			ch[num++]=a[i];
		}
	}
	for(int i=0;i<num;i++){
		printf("%c",ch[i]);
	}
	printf("\n");
	return 0;
}           

繼續閱讀