Deli Deli

From Progteam

Revision as of 23:55, 28 April 2009 by Andrew.stone (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Checkmark.jpg This problem has been solved by andrew.stone.



Deli Deli
Problem Number 3366
Sorter: Uncategorized
Source: Unknown
Link: http://acm.pku.edu.cn/JudgeOnline/problem?id=3366




Contents

Problem Information

Problem Name: Deli Deli Problem Number on PKU: 3366 Synopsis: Pluralize some words given some irregulars.

Solver Information

Solver: Andrew Stone, Dan Grippi Date: April 28, 2009

General Strategy

  1. Parse some strings and pluralize them...

Java Solution

import java.util.*;

public class Main{
	public static Scanner in;
	
	public static void main(String[] args) {
		in=new Scanner(System.in);
		
		doStuff();
	}

	public static void doStuff(){
		int irrs=in.nextInt();
		int next=in.nextInt();
		String line;
		String [] split;
		
		
		Hashtable<String,String> irregulars = new Hashtable<String,String>();
		
		for (int i = 0; i < irrs; i++) {
			line = in.nextLine();
			irregulars.put(in.next(), in.next());
		}
		
		solve(irregulars);
	}

	public static void solve(Hashtable<String,String> irregs){
		String word, last2, last, suffix;
		while (in.hasNext()) {
			word = in.next();
			
			if (irregs.containsKey(word)) {
				System.out.println(irregs.get(word));
			} else {
				last2 = word.substring(word.length() - 2);
				last = word.substring(word.length() - 1);
				
				if (last.equals("y") && last2.charAt(0)  != 'a' && last2.charAt(0)  != 'e' && last2.charAt(0)  != 'i' && last2.charAt(0)  != 'o' && last2.charAt(0)  != 'u') {
					System.out.println(word.substring(0, word.length() - 1)+"ies");
				} else if (last2.equals("ch") || last2.equals("sh")) {
					System.out.println(word+"es");
				} else if (last.equals("o") || last.equals("s") || last.equals("x")) {
					System.out.println(word+"es");
				} else {
					System.out.println(word+"s");
				}
			}
		}
	}
}

Additional Remarks

Memory: 2556K Time: 188MS

This solution IS NOT as efficient as it can be.

Personal tools