zoukankan      html  css  js  c++  java
  • 字符处理 沼跃鱼

    这是一道字符处理的问题;

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 #include <string.h>
     4 #include <math.h>
     5 
     6 int a[211];
     7 void Find (char *ch1, char *ch3);
     8 
     9 int main ()
    10 {
    11     int i, l1, k;
    12     char ch[210], ch1[210];
    13     char ch3[]= {"marshtomp"};
    14     while (gets(ch)!=NULL)
    15     {
    16         l1 = strlen(ch);
    17         k = 0;
    18         for(i = 0; i<l1; i++)
    19         {
    20             if(ch[i]>='A' && ch[i]<='Z')
    21                 ch1[i] = ch[i]+32;
    22             else
    23                 ch1[i] = ch[i];
    24         }
    25         Find (ch1, ch3);
    26         for(i = 0; i<l1; i++)
    27         {
    28             if (i == a[k])
    29             {
    30                 printf("fjxmlhx");
    31                 i+=8;
    32                 k++;
    33             }
    34             else
    35                 printf("%c", ch[i]);
    36         }
    37         printf("
    ");
    38     }
    39     return 0;
    40 }
    41 void Find (char *ch1, char *ch3)
    42 {
    43     int i, j, len, l1;
    44     int k;
    45     len = strlen(ch1)-strlen(ch3);
    46     l1 = strlen(ch3);
    47     k = 0;
    48     memset(a, -1, sizeof(a));
    49     for (i = 0; i<len; i++)
    50     {
    51         if(ch1[i] == ch3[0])
    52         {
    53             for (j = 1; j<l1; j++)
    54             {
    55                 if(ch1[i+j] != ch3[j])
    56                     break;
    57             }
    58             if (j == l1)
    59             {
    60                 a[k] = i;
    61                 k++;
    62             }
    63             j = 0;
    64         }
    65     }
    66 }

    代码如上;

    Description

    fjxmlhx每天都在被沼跃鱼刷屏,因此他急切的找到了你希望你写一个程序屏蔽所有句子中的沼跃鱼(“marshtomp”,不区分大小写)。
    为了使句子不缺少成分,统一换成 “fjxmlhx”。

    Input
    输入包括多行。每行是一个字符串,长度不超过200。
    一行的末尾与下一行的开头没有关系。
    Output
    输出包含多行,为输入按照描述中变换的结果。
    Sample Input
    The Marshtomp has seen it all before.
    marshTomp is beaten by fjxmlhx!
    AmarshtompB
    Sample Output
    The fjxmlhx has seen it all before.
    fjxmlhx is beaten by fjxmlhx!
    AfjxmlhxB
    Hint

    不存在mar shto mp这种用空格分开的情况。

    有可能一个句子中有两个以上“marshtomp”。

    Source
    哈尔滨理工大学第五届ACM程序设计竞赛
  • 相关阅读:
    Django contenttypes组件
    Django admin组件使用
    Django 信号
    Django 中间件
    Django 分页组件替换自定义分页
    Django ORM操作补充
    Django ORM 操作2 增删改
    Django 序列化
    JavaScript
    CSS 属性
  • 原文地址:https://www.cnblogs.com/yishilin/p/4379141.html
Copyright © 2011-2022 走看看