Skip to content

Instantly share code, notes, and snippets.

@micahstairs
Last active August 29, 2015 14:27
Show Gist options
  • Save micahstairs/cfba4812077862f0bb20 to your computer and use it in GitHub Desktop.
Save micahstairs/cfba4812077862f0bb20 to your computer and use it in GitHub Desktop.
Solution for String Manipulation 2 [Programming Competition Problems] (https://www.youtube.com/watch?v=bC7PYm9s1Vc)
import java.util.*;
public class CentauriPrime {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = Integer.valueOf(sc.nextLine());
for (int i = 1; i <= t; i++) {
String country = sc.nextLine().toLowerCase();
char lastLetter = country.charAt(country.length() - 1);
String ruler;
switch (lastLetter) {
case 'y':
ruler = "nobody";
break;
case 'a': case 'e': case 'i': case 'o': case 'u':
ruler = "a queen";
break;
default:
ruler = "a king";
break;
}
String str = String.format("Case #%d: %s is ruled by %s.", i, country, ruler);
System.out.println(str);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment