参考代码:
//// 1168 字符串的查找删除2.cpp// Jobdu//// Created by PengFei_Zheng on 25/04/2017.// Copyright © 2017 PengFei_Zheng. All rights reserved.// #include#include #include #include #include #define MAX_SIZE 1001 using namespace std; char str[MAX_SIZE]; int main(){ gets(str); string a = str; int lena = (int)a.size(); for(int i = 0 ; i < lena ; i++){ a[i] = tolower(a[i]); } while(gets(str)){ string b = str; string c = b; int lenb = (int)b.size(); for(int i = 0 ; i < lenb ; i++){ b[i]=tolower(b[i]); } int pos = (int)b.find(a,0); while(pos!=string::npos){ c.erase(pos,lena); b.erase(pos,lena); pos = (int)b.find(a,pos); } pos = (int)c.find(' ',0); while(pos!=string::npos){ c.erase(pos,1); pos = (int)c.find(' ',0); } cout< <
参考代码2:
//// 1168 字符串的查找删除.cpp// oj//// Created by PengFei_Zheng on 03/04/2017.// Copyright © 2017 PengFei_Zheng. All rights reserved.// #include#include #include #include char c[1001];int match_len = 0;char ch; using namespace std; int main(){ scanf("%s",c); int len = (int)strlen(c);//the length of pattern ch=getchar();//remove the space or return after input c while((ch=getchar())!=EOF){ //get each char if(tolower(ch)==tolower(c[match_len])) { //find same character match_len++;//move index to next position if(match_len>=len) match_len=0;// reinitation ,if ch==c[len-1] then next i will be assigned len } else{ if(match_len==0){ //now position is not satisfy if(ch!=' ') cout<