zoukankan      html  css  js  c++  java
  • 字符串过滤程

    /*
    题目:
    通过键盘输入一串小写字母(a~z)组成的字符串。请编写一个字符串过滤程序,若字符串中出现多个相同的字符,将非首次出现的字符过滤掉。
    比如字符串“abacacde”过滤结果为“abcde”。
    要求实现函数: 
    void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);
    【输入】 pInputStr:  输入字符串
             lInputLen:  输入字符串长度         
    【输出】 pOutputStr: 输出字符串,空间已经开辟好,与输入字符串等长;
    【注意】只需要完成该函数功能算法,中间不需要有任何IO的输入输出
    示例 
    输入:“deefd”        输出:“def”
    输入:“afafafaf”     输出:“af”
    输入:“pppppppp”     输出:“p”
    */
    
    #include<iostream>
    using namespace std;
    bool exist(char *p,char c);
    void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr);
    int main(void)
    {
        char *input="deeef";
        char output[10];
        stringFilter(input,5,output);
        cout<<output<<endl;
        getchar();
        
    }
    
    bool exist(char *p,char c)
    {
        while(*p)
        {
            if(*p++==c)
                return true;
        }
        return false;
    }
    void stringFilter(const char *pInputStr, long lInputLen, char *pOutputStr)
    {
        char *p=pOutputStr;
        *p++=*pInputStr++;
        *p='';
        while(*pInputStr)
        {
    
            if(!exist(pOutputStr,*pInputStr))//判断*pInputStr是否已经出现
            {
                *p++=*pInputStr++;
                *p='';
            }
            else
                pInputStr++;
        }
    
    }
  • 相关阅读:
    echarts图表重设尺寸
    文本文档中各字母出现次数汇总(java)
    30道随机运算
    随机生成验证码
    原码,反码,补码
    动手动脑(一)
    模拟银行ATM系统(基础版)
    2018暑期周总结报告(五)
    2018暑期周总结报告(四)
    2018暑期周总结报告(三)
  • 原文地址:https://www.cnblogs.com/qianwen/p/3828427.html
Copyright © 2011-2022 走看看