Last active
August 29, 2015 14:27
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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