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程序设计竞赛
  • 相关阅读:
    理解glance
    基于Kubernetes(k8s)的RabbitMQ 集群
    docker最佳实践-----美团点评的分享
    成功搭建云计算的关键技巧------过完年第一篇
    从SDN鼻祖Nicira到VMware NSX 网络虚拟化平台的简单探讨
    openstack多region介绍与实践---转
    openstack架构
    kvm网络虚拟化
    kvm虚拟化操作
    html-from提交表单
  • 原文地址:https://www.cnblogs.com/yishilin/p/4379141.html
Copyright © 2011-2022 走看看