⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toj_2911_1.cpp

📁 Tianjin University Online Judge 的80多道题目 .
💻 CPP
字号:
/*2911.   Deli Deli Time Limit: 1.0 Seconds   Memory Limit: 65536KTotal Runs: 32   Accepted Runs: 27Mrs. 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.InputThe 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').OutputPrint N lines of output, where the ith line is the plural form of the ith input word.Sample Input3 7rice ricespaghetti spaghettioctopus octopiricelobsterspaghettistrawberryoctopuspeachturkeySample OutputricelobstersspaghettistrawberriesoctopipeachesturkeysSource: University of Ulm Local Contest 2007*/#include<cstdio>#include<cstring>#define WORDLEN 30bool findInDict( char const  aWord[] , int& position , char const  dict[][ 2 ][ WORDLEN ] , int const l ){  int i;  bool flag;  flag = false;  for ( i = 0; i < l; i++ )    {      if ( strcmp( dict[ i ][ 0 ] ,  aWord ) == 0 )	{	  position = i;	  flag = true;	  break;	}    }  return flag;}	  int main(){  int i , j , l , n , position , len;  char dict[ 20 ][ 2 ][ WORDLEN ] , aWord[ WORDLEN ] , result[ WORDLEN ];  char last , last2[ 3 ];  scanf( "%d%d" , &l , &n  );  for ( i = 0; i < l; i++ )    {      scanf( "%s%s" , dict[ i ][ 0 ] , dict[ i ][ 1 ] );    }  for ( i = 0; i < n; i++ )    {            scanf ( "%s" , aWord );	    len = strlen( aWord );	    last = aWord[ len - 1 ];	    strcpy( last2 , &aWord[ len - 2 ] );      if ( findInDict( aWord , position , dict , l ) )	{	  strcpy( result , dict[ position ][ 1 ] );	}      else if ( last2[ 0 ] != 'a' && last2[ 0 ] != 'i' && last2[ 0 ] != 'o' && last2[ 0 ] != 'e' && last2[ 0 ] != 'u' &&last  == 'y' )	{	  strcpy( &aWord[ len - 1 ] , "ies" );	  strcpy( result , aWord );	}      else if ( last == 'o' || last == 's' || last == 'x' || strcmp( last2 , "ch" ) == 0  || strcmp( last2 , "sh" ) == 0 )	{	  strcpy( &aWord[ len ] , "es" );	  strcpy( result , aWord );	}      else	{	  strcpy( &aWord[ len ] , "s" );	  strcpy( result , aWord );	}      printf( "%s\n" , result );    }  return 0;}	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -