删除字符串中的数字

来源:互联网 发布:网络管理师考试 编辑:程序博客网 时间:2024/05/17 01:32
#include <iostream>using namespace std;void RemoveNumber(char * str){    char *read = str;    char *write = str;    while (*read != '\0')    {        if (*read < '0' || *read > '9')        {            *write = *read;            write++;        }        read++;    }    *write = '\0';}int main(){    char str[] = "a88b";    RemoveNumber(str);    cout<<str<<endl;    return 0;}


a 8  8  b

a b  8  b

a b \0  b


畅游笔试题,复杂度O(n),STL remove算法。



0 0
原创粉丝点击