1. 

/**
* Angewandte Mathematik, SS09, IFB 2C
* ACM Problem #11233 (Deli Deli)
* Link: http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2174
*
* @author Christian Posselt
* @author Jonathan Schubert
* @version 1.0, 04/07/2009
*
* Status : Accepted
* Runtime: 0.160
*/
import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;


public class Main
{
public static void main(String[] args)
{
BufferedInputStream bin = new BufferedInputStream(System.in);
Scanner sc = new Scanner(bin);
StringBuilder builder = new StringBuilder();
int num_irreg, num_prod;

//vocals for grammar
ArrayList<String> vocals = new ArrayList<String>();
vocals.add("a");
vocals.add("e");
vocals.add("i");
vocals.add("o");
vocals.add("u");

//replace rules
HashMap<String,String> forms = new HashMap<String,String>();
forms.put("y", "ies");
forms.put("o", "oes");
forms.put("sh", "shes");
forms.put("s", "ses");
forms.put("ch", "ches");
forms.put("x", "xes");

num_irreg = sc.nextInt();
num_prod = sc.nextInt();

HashMap<String,String> plural = new HashMap<String,String>();

//save irregular words in hashmap
for(int i=0;i<num_irreg;i++)
{
String singular = sc.next();
String plurals = sc.next();
plural.put(singular, plurals);
}

for(int i=1;i<=num_prod;i++)
{
String singular = sc.next();
String end = singular.substring(singular.length()-2, singular.length());
String end_single = end.substring(end.length()-1, end.length());
//is plural
if(plural.containsKey(singular))
{
builder.append(plural.get(singular));
}
//are the last two chars in grammar rules
else if(forms.containsKey(end))
{
builder.append(singular.substring(0, singular.length()-2));
builder.append(forms.get(end));
}
//are the last chars in grammar rules
else if(forms.containsKey(end_single))
{
//if last char y append y and the char before y is a vocal append s
if(end_single.equals("y") && vocals.contains(end.substring(end.length()-2,end.length()-1)))
{
builder.append(singular);
builder.append("s");
}
else //use the grammar rules
{
builder.append(singular.substring(0, singular.length()-1));
builder.append(forms.get(end_single));
}
}
else //no special rules append s
{
builder.append(singular);
builder.append("s");
}

builder.append("\n");
}

System.out.print(builder.toString());
}

}

2.





/**
 * Angewandte Mathematik, SS09, IFB 2C
 * ACM Problem #11233 - Deli Deli
 *
Link:
http://icpcres.ecs.baylor.edu/onlinejudge/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=2174
 *
 * @author Mohr
 * @author Schirm
 * @author Mathauser
 * @version 1.0, 04/08/2009
 *
 * Status : Accepted
 * Runtime: 0.090
 */
 
 
import java.io.*;
import java.util.Arrays;

 
public class Main
{
 
    @SuppressWarnings("null")
    public static void main(String...args)    throws IOException
    {
        
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        String line = reader.readLine();
        String[] numbers = line.split(" ");
        
        int count1 = Integer.parseInt(numbers[0]);
        int count2 = Integer.parseInt(numbers[1]);
        
        
        String[][] plural = new String[count1][2];
        for(int i = 0; i < count1; i++){
            line = reader.readLine();
            //System.out.println(Arrays.toString(line.split(" ")));
            plural[i] = line.split(" ");
        }
        //System.out.println(Arrays.toString(plural));
        String output = "";
        for(int i = 0; i < count2; i++)        // zeile für zeile
        {
            boolean inList = false;
            line = reader.readLine();
            
            for(int j = 0; j < Integer.parseInt(numbers[0]); j++){
                if(plural[j][0].equals(line))    {
                    System.out.println(plural[j][1]);
                    inList = true;
                    break;
                }
            }
            if(!inList){
                char last = line.charAt(line.length()-1);
                char preLast = line.charAt(line.length()-2);
                String last2 = line.substring(line.length()-2, line.length());
                //System.out.println(last2);
                
  
             if(last == 'y' && (preLast != 'o'&& preLast != 'i'&& preLast != 'a'&& preLast != 'e'&& preLast != 'u'))
                    System.out.println(line.substring(0, line.length()-1)+"ies");
                else if(last == 'o' || last == 's' || last == 'x')
                    System.out.println(line+"es");
                else    if(last2.equals("ch") || last2.equals("sh"))
                    System.out.println(line+"es");
                else
                    System.out.println(line+"s");
                    
            }
            
            //System.out.println(output);
            
        }
        
        
    }
}