登 录
//============================================================================ // Name : 100题之在字符串中删除特定的字符.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include<stdio.h> #include<stdlib.h> using namespace std; const int LEN=256; void DeleteChars(char* pSource, const char* pDelete) { int number[LEN]; int length=strlen(pDelete); for(int i=0;i<LEN;i++) { number[i]=0; } for(int i=0;i<length;i++) { number[(int)pDelete[i]]=1; } char *first=pSource; char *last=pSource; while(*first!='/0') { if(number[(int)(*first)]!=1) { (*last)=(*first); last++; } first++; } (*last)='/0'; length=strlen(pSource); for(int i=0;i<length;i++) cout<<pSource[i]<<" "; cout<<endl; } int main() { char pSource[19]="They are students."; char pDleste[6]="aeiou"; DeleteChars( pSource, pDleste); return 0; }
抱歉!评论已关闭.