字符串中删除特定字符
2014-10-11 11:16
267 查看
痛心的感觉!
题目要求:
删除给定字符串中的‘a' 字符,返回原字符串。 遍历一次。
_____________________________________________________________________________
删除 'a' , 'bc'
题目要求:
删除给定字符串中的‘a' 字符,返回原字符串。 遍历一次。
<span style="font-size:14px;">#include <iostream> #include <string.h> using namespace std; char * deleteChar(char * str) { char * pFast , *pSlow; int length = strlen(str); pFast = pSlow = str; while(length--) { if(*pFast == 'a') { ++pFast; } else { *pSlow = *pFast; pSlow ++; pFast ++; } } *pSlow = '\0'; return str; } int main() { char str[]= {"AabcdaaMMaWWacD"}; cout <<str<<endl; cout<< deleteChar(str); return 0; } </span>
_____________________________________________________________________________
删除 'a' , 'bc'
#include <iostream> #include <string.h> using namespace std; char * deleteChar(char * str) { char * pFast , *pSlow; int length = strlen(str); pFast = pSlow = str; while(length--) { char temp; if(*pFast == 'a') { ++pFast; } else if( *pFast == 'b') { temp = *(pFast +1); if( temp == 'c') { pFast +=2; } else { ++pFast; } } else { *pSlow = *pFast; pSlow ++; pFast ++; } } *pSlow = '\0'; return str; } int main() { char str[]= {"cabbabcdefag"}; cout <<str<<endl; cout<< deleteChar(str); return 0; }
相关文章推荐
- 在字符串中删除特定的字符
- 在字符串中删除特定的字符
- 程序员面试题精选100题(36)-在字符串中删除特定的字符
- 在字符串中删除特定的字符(字符串)。
- 在字符串中删除特定的字符
- 在字符串中删除特定的字符
- 在字符串中删除特定的字符
- 程序员面试题精选100题(36)-在字符串中删除特定的字符
- 【每日面试题】在字符串中删除特定的字符
- (12) 转载:在字符串中删除特定的字符
- 字符串中删除特定的字符
- 程序员面试100题之三十六,在字符串中删除特定的字符
- 【算法20】在字符串中删除特定的字符
- 程序员面试题精选--在字符串中删除特定的字符
- 在字符串中删除特定的字符
- 算法题4 在字符串中删除特定的字符
- 算法题40 在字符串中删除特定的字符。
- 在字符串中删除特定的字符
- 在字符串中删除特定的字符
- [字符串]在字符串中删除特定的字符