zoukankan      html  css  js  c++  java
  • codeup-字符串的查找删除

    1808: 字符串的查找删除

    Time Limit: 1 Sec  Memory Limit: 32 MB
    Submit: 2002  Solved: 574
    [Submit][Status][Web Board][Creator:Imported]

    Description

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

    Input

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

    Output

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

    Sample Input

    in
    #include 
    int main()
    {
    
    printf(" Hi ");
    }

    Sample Output

    #clude
    tma()
    {
    
    prtf("Hi");
    }

    HINT

    注:将字符串中的In、IN、iN、in删除。

     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int main(){
     5     char c[100];
     6     char s[1000];
     7     gets(c);
     8     int len1 = strlen(c), len2;
     9     //将c[i]全部转化为小写 
    10     for(int i=0; i<len1; i++){
    11         if(c[i]>='A'&&c[i]<='Z'){
    12             c[i] = c[i] + 32;
    13         }
    14     }
    15     while(gets(s)){
    16         len2 = strlen(s);
    17         if(len2>=len1){
    18             //对这个匹配过程不是很理解 
    19             for(int i=0, k=0; i<len2; ){
    20                 //在匹配时,i不变,不匹配时,i自增! 
    21                 if(s[i+k]==c[k] || s[i+k]==c[k]-32){
    22                     k++;
    23                     if(k==len1){
    24                         i = i + k; //在后k项满足时,i增加k 
    25                         k = 0; 
    26                     }
    27                 }else{
    28                     if(s[i]!=' '){
    29                         printf("%c", s[i]);
    30                     }
    31                     i++;
    32                     k = 0;
    33                 }
    34             }
    35         }else{
    36             for(int i=0; i<len2; i++){
    37                 if(s[i]!=' '){
    38                     printf("%c", s[i]);
    39                 }
    40             }
    41         }
    42         printf("
    ");
    43     }
    44     return 0;
    45 }
  • 相关阅读:
    Python RabbitMQ
    对于一些概念的澄清
    Python没有执行__init__
    python中的gil是什么?
    linux命令行快捷键
    关于异步:再次思考和澄清
    greenlet代码解读
    关于协程
    设计模式-重复重复的设计模式
    组合模式-虚有其表的模式
  • 原文地址:https://www.cnblogs.com/heyour/p/12149886.html
Copyright © 2011-2022 走看看