【端午小练】HDU1804-Deli Deli

简介:

Deli Deli
Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1392    Accepted Submission(s): 757


Problem Description
Mrs. Deli is running the delicatessen store "Deli Deli". Last year Mrs. Deli has decided to expand her business and build up an online store. She has hired a programmer who has implemented the online store.

Recently some of her new online customers complained about the electronic bills. The programmer had forgotten to use the plural form in case that an item is purchased multiple times. Unfortunaly the programmer of Mrs. Deli is on holiday and now it is your task to implement this feature for Mrs. Deli. Here is a description how to make the plural form:

1. If the word is in the list of irregular words replace it with the given plural.
2. Else if the word ends in a consonant followed by "y", replace "y" with "ies".
3. Else if the word ends in "o", "s", "ch", "sh" or "x", append "es" to the word.
4. Else append "s" to the word.

 

Input
The first line of the input file consists of two integers L and N (0 ≤ L ≤ 20, 1 ≤ N ≤ 100). The following L lines contain the description of the irregular words and their plural form. Each line consists of two words separated by a space character, where the first word is the singular, the second word the plural form of some irregular word. After the list of irregular words, the following N lines contain one word each, which you have to make plural. You may assume that each word consists of at most 20 lowercase letters from the english alphabet ('a' to 'z').


 

Output
Print N lines of output, where the ith line is the plural form of the ith input word.


 

Sample Input
3 7
rice rice
spaghetti spaghetti
octopus octopi
rice
lobster
spaghetti
strawberry
octopus
peach
turkey
 

Sample Output
rice
lobsters
spaghetti
strawberries
octopi
peaches
turkeys
 

Source
HDOJ 2007 Summer Exercise(1)

 

字符串操作,水题
AC代码:

#include<stdio.h>
#include<string.h>
char a[100][50],p1[50][50],p2[50][50];
int main()
{
    int i,j,n,m,k,flag;
    scanf("%d %d",&n,&m);
    {
       for(i=0;i<n;i++)
       {
          //getchar();
          scanf("%s %s",p1[i],p2[i]);
       }
       for(i=0;i<m;i++)
       {
          //getchar();
          scanf("%s",a[i]);
       }
       for(i=0;i<m;i++)
       {
          flag=0;
          for(j=0;j<n;j++)
          {
             if(strcmp(a[i],p1[j])==0)
             {
                 memset(a[i],0,sizeof(a[i]));
                 strcpy(a[i],p2[j]);  
                 flag=1;             
             }
          }
          if(flag==0)
          {
             k=strlen(a[i]);
             if(a[i][k-1]=='y'&&a[i][k-2]!='a'&&a[i][k-2]!='e'&&a[i][k-2]!='i'&&a[i][k-2]!='o'&&a[i][k-2]!='u')
             {
                a[i][k-1]='i';
                a[i][k]='e';
                a[i][k+1]='s';
             }
             else
             if(a[i][k-1]=='o'||a[i][k-1]=='s'||(a[i][k-1]=='h'&&a[i][k-2]=='c')||(a[i][k-1]=='h'&&a[i][k-2]=='s')||a[i][k-1]=='x')
             {
                a[i][k]='e';
                a[i][k+1]='s';
             }
             else
             a[i][k]='s';
          }
       }
        for(i=0;i<m;i++)
        printf("%s\n",a[i]);
    }
    return 0;
}
相关文章
畅通工程 HDU - 1232
畅通工程 HDU - 1232
54 0
HDU-2897,邂逅明下(巴什博弈)
HDU-2897,邂逅明下(巴什博弈)
|
算法
HDU - 2063: 过山车
HDU - 2063: 过山车
111 0
|
人工智能 测试技术
|
定位技术
洛谷 P2805 BZOJ 1565 植物大战僵尸
题目描述 Plants vs. Zombies(PVZ)是最近十分风靡的一款小游戏。Plants(植物)和Zombies(僵尸)是游戏的主角,其中Plants防守,而Zombies进攻。该款游戏包含多种不同的挑战系列,比如Protect Your Brain、Bowling等等。
892 0
|
Java 测试技术
HDU 1232 畅通工程
畅通工程 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 50540    Accepted Submission(s): 26968 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇。
1001 0
|
人工智能 Java C++
HDU 3785 寻找大富翁
寻找大富翁 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6716    Accepted Submission(s): 2492 Problem Description 浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁.
1040 0