遍历一遍S1,建立link到next相同的ascii码,从32到126 ASCII码搜索S2,若找到则删除S1中相应的character
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <cstdio> #include <cstring> int first[128],last[128]; char s[10001],sub[10001]; int next[10001]; void subtract(char c){ for(int p=first[c];p>=0;p=next[p]) s[p]=0; first[c]=-1; } int main(){ int n; for(int i=32;i<127;i++) first[i]=-1; for(n=0;(s[n]=getchar())!='\n';n++){ char c=s[n]; if(first[c]<0) first[c]=n; else next[last[c]]=n; last[c]=n; next[n]=-1; } s[n]=0; gets(sub); for(int i=32;i<127;i++) if(strchr(sub,i)) subtract(i); for(int i=0;i<n;i++) if(s[i]) printf("%c",s[i]); return 0; } |