1050. String subtraction (20) Time limit 10 ms memory limit 32000 kb code length limit 16000 B discriminant program standard
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 itFast.
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.
Recommendation index :※
Source: http://pat.zju.edu.cn/contests/pat-a-practise/1050
Simply think about it.
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;#define N 128int main(){int i=0,sum;bool is_exist[N];char ch;char str[10000];memset(is_exist,0,sizeof(is_exist));while(scanf("%c",&ch)&&ch!='\n'){is_exist[ch]=true;str[i++]=ch;}sum=i;while(scanf("%c",&ch)&&ch!='\n'){is_exist[ch]=false;}i=0;while(i<sum){if(is_exist[str[i]]!=false)printf("%c",str[i]);i++;}return 0;}