zoukankan      html  css  js  c++  java
  • 剑指Offer:从第一个字符串中删除第二个字符串中出现过的所有字符

    // 从第一个字符串中删除第二个字符串中出现过的所有字符
    
    #include <stdio.h>
    
    char* remove_second_from_first( char *first, char *second )
    {
        if( first == NULL || second == NULL )
        {
            printf("first or/and second should not be NULL
    ");
            return NULL;
        }
    
        char flag[256]={0};
        char *p, *q;
    
        p = second;
        while( *p != '' )
            flag[*p++] = 1;
    
        p = q = first;
        while( *q != '' )
        {
            if( flag[*q] == 1 )
            {
                q++;
                continue;
            }
            *p++ = *q++;
        }
        *p = '';
    
        return first;
    }
    
    int main(void)
    {
        char s1[101], s2[101];
        scanf("%s",s1);
        scanf("%s",s2);
        char *result = remove_second_from_first(s1,s2);
        printf("%s
    ",result);
    
        return 0;
    }
  • 相关阅读:
    指针理解
    http和https区别
    js 日历控件
    Linux 目录详解!(转)
    互换位置输出
    晨时跌荡起伏的心情
    c++冒泡排序
    游标使用
    防止Sql注入
    ssl加密原理
  • 原文地址:https://www.cnblogs.com/DayByDay/p/3864424.html
Copyright © 2011-2022 走看看