• 1168.字符串的查找删除


    题目描述

    给定一个短字符串(不含空格),再给定若干字符串,在这些字符串中删除所含有的短字符串。

     
    输入

    输入只有1组数据。
    输入一个短字符串(不含空格),再输入若干字符串直到文件结束为止。

     
    输出

    删除输入的短字符串(不区分大小写)并去掉空格,输出。

     
    样例输入
    in
    #include
    int main()
    {
    printf(" Hi ");
    }
     
    样例输出
    #clude
    tma()
    {
    prtf("Hi");
    }

    #include<stdio.h>
    #include<string.h>
    #include<ctype.h>
     
    int main()
    {
        char s1[100],ch;
        gets(s1);
        int t=0;
        while((ch=getchar())!=EOF)
        {
            if(tolower(s1[t])==tolower(ch))
            {
                t++;
                if(t>=strlen(s1))
                t=0;
            }
            else {
                if(t==0)
                {
                    if(ch!=' ') putchar(ch);
                } 
                else {
                    for(int k=0;k<t;k++)
                        putchar(s1[k]);
                    t=0;
                    if(ch!=' ') putchar(ch);
                }
                }         
        } 
        return 0;
    }

    用c++写有点难,需要处理的细节太多。python就很简单了。。

  • 相关阅读:
    实验报告2
    实验三 网络欺骗技术
    实验3
    心理魔术
    实验报告
    实验4
    实验5
    实验四恶意代码
    网络对抗技术 实验一
    实验二
  • 原文地址:https://www.cnblogs.com/bernieloveslife/p/9735118.html
Copyright © 2020-2023  润新知