Wednesday 22 June 2011

Simple Quiz


Problem

Back in the old days before the creation of the mighty Centauri Republic, the planet Centauri Prime was split into several independent kingdoms. The kingdom of Mollaristan was ruled by king Loatold, while the kingdom of Auritania was under the rule of queen Elana. In fact, it just so happened that every kingdom whose name ended in a consonant was ruled by a king, while every kingdom whose name ended in a vowel was ruled by a queen. Also because of an amazing coincidence, all kingdoms whose named ended in the letter 'y' were constantly in a state of turmoil and were not ruled by anyone. Can you write a program that will determine the current rulers of several countries, given the countries' names?

Input

The first line of the input gives the number of test cases, TT lines follow, each one containing the name of one country. Country names will consist of only lower case English letters, starting with a capital letter. There will be no other characters on any line, and no empty lines.

Output

For each test case, output one line containing "Case #xC is ruled by Y.", where x is the case number (starting from 1), C is the country name, and Y is either "a king", "a queen" or "nobody".





Code:


package com.quiz.sample;


import java.util.Scanner;


/**
 * 
 * @author DurgaPrasad
 *
 */
public class VowelConsonent {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("enter the number of testcases");
int num =scan.nextInt();
for(int i=1;i<=num+1;i++){
System.out.println("enter the name");
String name=scan.next();
String last=name.substring(name.length()-1);
if(last.equals("y")){
System.out.println("case :"+i+" " +name+" "+"is ruled by NO Ruler");
}
else if("aeiou".contains(last)){
System.out.println("case :"+i+" "+name+" "+"is ruled by queen");
}else{
System.out.println("case :"+i+" "+name+" "+"is ruled by king");
}
}
}
}


No comments:

Post a Comment