-
Title Description:
-
Given a short string (without spaces), and given a number of strings, delete the contained short string in these strings.
-
Input:
-
Enter only 1 sets of data.
Enter a short string (with no spaces), and then enter several strings until the end of the file.
-
Output:
-
Delete the input short string (case insensitive) and remove the whitespace, output.
-
Sample input:
-
in#include int main () {printf ("Hi");}
-
Sample output:
-
#cludetma () {prtf ("Hi");}
-
-
Tips:
-
Note: The In, in, in, and in of the string are deleted.
#include <iostream>#include<string.h>using namespacestd;Const intmaxn=1005;CharA[MAXN],B[MAXN];intLena,lenb;intNEX[MAXN];BOOLSame (CharCH1,CharCH2) { if('A'<=ch1&&ch1<='Z') ch1+= +; if('A'<=ch2&&ch2<='Z') ch2+= +; returnch1==CH2; }voidGetNext () {intI=0; intk=-1; nex[0]=-1; while(i<LenB) { if(k==-1||Same (B[k],b[i])) {i++; K++; Nex[i]=K; } Elsek=Nex[k]; }}intVIS[MAXN];voidKMP () {intI=0; intj=0; while(i<Lena) { if(j==-1||Same (A[i],b[j])) {i++; J++; } Elsej=Nex[j]; if(j==LenB) { intl=i-J; for(intz=l;z<l+lenb;z++) {Vis[z]=1; } J=0; } }}intMain () {CIN>>b; LenB=strlen (b); GetNext (); Cin.Get(); while(Cin.getline (A,MAXN)) {Lena=strlen (a); memset (Vis,0,sizeof(VIS)); KMP (); for(intI=0; i<lena;i++) { if(a[i]==' '|| Vis[i])Continue; cout<<A[i]; } cout<<Endl; } return 0;}
2009 Beihang: Finding and deleting strings