zoukankan      html  css  js  c++  java
  • [两个指针]删除字符串中指定的字符

    删除字符串中指定的字符

    输入 char *a = "abc123";

       char *del = "a13";

    利用两个字符指针的方式,pslow,pfast;

    char *pslow,*pfast;

    两个指针一开始都指向字符串的开始位置;

    pfast开始遍历字符串,

    if(*pfast==指定字符){////这里疑惑的地方就是,pslow什么时候向前滑行

      将pfast所指字符,移到pslow的位置(就是赋值操作,*pslow = *fast)

      pslow++;

          pfast++;

    }else{

      pfast++;

    }

    ///==================

    #include <iostream>
    #include <stdio.h>
    #include <cstdio>
    #include <string>
    #include <string.h>
    #include <vector>
    #include <map>
    #include <unordered_map>
    #include <unordered_set>
    #include <algorithm>
    #include <list>
    #include <limits.h>
    #include <set>
    //#include "xiaozhao.h"
    #include <numeric>
    #include <bitset>
    #include <iomanip>
    #include <queue>
    #include <math.h>
    #include <sstream>
    #include <stdio.h>
    #include <list>
    #include <stack>
    using namespace std;
    
    char TheArray[256];
    
    void InitTheArray(const char* p){
        while(''!=*p){
            TheArray[*p++] = 1;
        }
    }
    
    void ProcessTheString(char *szDestination){
        char *pFast;
        char *pSlow;
    
        pFast = pSlow = szDestination;
    
        while(''!=*pFast){
            if(0==TheArray[*pFast]){
                *pSlow=*pFast;
                pSlow++;
                pFast++;
            }else{
                pFast++;
            }
        }///while
        *pSlow = '';
    }///Process
    
    int main()
    {
        //Cxiao c;
        //c.test();
        //freopen("input.txt", "r", stdin);
    
        char szDes[] = "they are students.";
        char szFind[] = "aeiou";
    
        InitTheArray(szFind);
        ProcessTheString(szDes);
        printf("%s
    ",szDes);
    
       return 0;
    }
  • 相关阅读:
    数据库拉取附件到本地
    Https工具类
    AES加密算法
    DES加密算法
    Http工具类,Lz提供
    接口调用工具类
    autofac生命周期入门(如何避免内存泄漏)
    ASP.NET异步
    Global Error Handling in ASP.NET Web API 2(webapi2 中的全局异常处理)
    ado.net EF学习系列----深入理解查询延迟加载技术(转载)
  • 原文地址:https://www.cnblogs.com/li-daphne/p/6014592.html
Copyright © 2011-2022 走看看