内部赛 3 D Deli Deli

来源:互联网 发布:java 判断日期相等 编辑:程序博客网 时间:2024/05/21 07:08

Deli Deli

Time Limit: 1000MS Memory limit:65536K

题目描述

Mrs. Deli isrunning the delicatessen store "Deli Deli". Last year Mrs. Deli hasdecided to expand her business and build up an online store. Shehas hired a programmer who has implemented the onlinestore.

Recently some of her new online customerscomplained about the electronic bills. The programmer had forgottento use the plural form in case that an item is purchased multipletimes. Unfortunaly the programmer of Mrs. Deli is on holiday andnow it is your task to implement this feature for Mrs. Deli. Hereis a description how to make the plural form:

  1. If the word is in the list of irregular wordsreplace it with the given plural.
  2. Else if the word ends in a consonant followedby "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.

输入

The first lineof the input file consists of two integers L and N (0≤ L ≤ 20, 1≤ N ≤ 100). The following L linescontain the description of the irregular words and their pluralform. Each line consists of two words separated by a spacecharacter, where the first word is the singular, the second wordthe plural form of some irregular word. After the list of irregularwords, the following N linescontain one word each, which you have to make plural. You mayassume that each word consists of at most 20 lowercase letters fromthe english alphabet (\'a\' to \'z\').


输出

Print N lines ofoutput, where the ith line isthe plural form of the ith inputword.


示例输入

3 7rice ricespaghetti spaghettioctopus octopiricelobsterspaghettistrawberryoctopuspeachturkey

示例输出

ricelobstersspaghettistrawberriesoctopipeachesturkeys

字符串的处理,注意看清题意!!!

代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
 char a[100];
 char b[100];
}str[25];

char str1[105];
int main()
{
 int n,m;
 int i,j,k;
 int len;
 scanf("%d%d",&n,&m); 
 for(i=0;i<n;i++)
 {
  scanf("%s%s",str[i].a,str[i].b);  
 }
 for(i=0;i<m;i++)
 {
  //memset(str1,0,sizeof(str1));
  scanf("%s",str1);  
  len=strlen(str1);
  for(j=0;j<n;j++)
  {
   if(strcmp(str1,str[j].a)==0)
   {
    printf("%s\n",str[j].b);
    break;
     
    
  }
  if(j>=n)
  {
   if(str1[len-1]=='y'&&str1[len-2]!='a'&&str1[len-2]!='e'&&str1[len-2]!='i'&&str1[len-2]!='o'&&str1[len-2]!='u')//注意这地方啊!!
   {
    for(k=0;k<len-1;k++)
     printf("%c",str1[k]);    
    printf("ies\n");
    
   }
   elseif(str1[len-1]=='o'||str1[len-1]=='s'||str1[len-1]=='x'||(str1[len-1]=='h'&&(str1[len-2]=='s'||str1[len-2]=='c')))
   {
    printf("%s",str1);
    printf("es\n");
    
   }
   else
   {
    printf("%s",str1);
    printf("s\n");
    
   }
  }

 }
 return 0;
}

原创粉丝点击