zoukankan      html  css  js  c++  java
  • hdu 1804

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1804

    题意:要把输入的英文字符串转化成复数的形式。

    mark:规则就是那4条。注意y的判断还要满足前一个字符不是元音字母(aeiou)就可以了。

    代码:

     1 # include <stdio.h>
     2 # include <string.h>
     3 
     4 
     5 char dict[25][2][25] ;
     6 int n, m ;
     7 
     8 
     9 int find(char s[])
    10 {
    11     int i ;
    12     for (i = 0 ; i < n ; i++)
    13         if (strcmp(s, dict[i][0]) == 0) return i ;
    14     return -1 ;
    15 }
    16 
    17 
    18 int consonant(char ch)
    19 {
    20     int i ;
    21     char tab[] = "aeiou" ;
    22     for (i = 0 ; i < 5 ; i++)
    23         if (ch == tab[i]) return 0 ;
    24     return 1 ;
    25 }
    26 
    27 
    28 int main ()
    29 {
    30     char str[25] ;
    31     int i, len, pos ;
    32     scanf ("%d%d", &n, &m) ;
    33     for (i = 0 ; i < n ; i++)
    34         scanf ("%s %s", dict[i][0], dict[i][1]) ;
    35     for (i = 0 ; i < m ; i++)
    36     {
    37         scanf ("%s", str) ;
    38         len = strlen(str) ;
    39         if ((pos=find(str)) != -1)
    40             puts (dict[pos][1]) ;
    41         else if (len > 1 && str[len-1] == 'y' && consonant(str[len-2]))
    42         {
    43             str[len-1] = '\0' ;
    44             strcat (str, "ies") ;
    45             puts (str) ;
    46         }
    47         else if (str[len-1] == 'o' || str[len-1] == 's' || str[len-1] == 'x'||
    48                 (len>1 &&(str[len-1] == 'h' && (str[len-2] == 'c' || str[len-2] == 's'))))
    49         {
    50             strcat (str, "es") ;
    51             puts (str) ;
    52         }
    53         else{
    54             strcat(str, "s") ;
    55             puts (str) ;
    56         }
    57     }
    58     return 0 ;
    59 }
  • 相关阅读:
    【python笔记】类
    【Marva Collins' Way】第八章
    【Marva Collins' Way】第七章
    【python笔记】包
    【python笔记】模块
    【Marva Collins' Way】第六章
    【Marva Collins' Way】第九章
    【python笔记】异常
    Axios跨域&封装接口
    js更新数据
  • 原文地址:https://www.cnblogs.com/lzsz1212/p/2479944.html
Copyright © 2011-2022 走看看