2012华为校园招聘机考试题总结(厦门大学) 渣渣的答案= =!

来源:互联网 发布:淘宝erp软件哪个好 编辑:程序博客网 时间:2024/04/27 21:10
/*删除子串,只要是原串中有相同的子串就删掉,不管有多少个,返回子串个数*/int delete_sub_str(const char *str,const char *sub_str,char *result){int count=0;for(int i=0;str[i]!='\0';i++){int j;int temp=i;for(j=0;str[i]==sub_str[j]&&sub_str[j]!='\0';i++,j++);if(sub_str[j]=='\0') {count++;i-=1;  //i会被多加1 所以要减掉}else{i=temp;cout<<"str["<<i<<"]"<<str[i]<<endl;*result++=str[i];   //把不是字串中的字符放到result中去}}*result='\0';return count;}int main(){int i=0;char result[100];i=delete_sub_str("abcdefgabcdefbcdefgh","bcdef",result);cout<<i<<endl;cout<<result;}

0 0
原创粉丝点击