Skip to content

Instantly share code, notes, and snippets.

@jonathanyee
Created August 19, 2014 07:27
Show Gist options
  • Select an option

  • Save jonathanyee/dfdce4870cb0533e8c95 to your computer and use it in GitHub Desktop.

Select an option

Save jonathanyee/dfdce4870cb0533e8c95 to your computer and use it in GitHub Desktop.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class GameOfThronesWarmup {
public static void main(String[] args) {
Scanner myScan = new Scanner(System.in);
String inputString = myScan.nextLine();
String ans = "";
char[] splittedInput = inputString.toCharArray();
Hashtable<Character, Integer> table = new Hashtable<Character, Integer>();
for (int i = 0; i < splittedInput.length; i++) {
System.out.println(splittedInput[i]);
if (!table.contains(splittedInput[i])) {
System.out.println("new character");
table.put(splittedInput[i], 1);
} else {
System.out.println("found existing");
table.put(splittedInput[i], table.get(splittedInput[i] + 1));
}
}
boolean isEven = inputString.length() % 2 == 0;
System.out.println("Is even: " + isEven);
int oddCounter = 0;
Set<Character> keys = table.keySet();
System.out.println("Key length " + keys.size());
for (Character key : keys) {
System.out.println("key: " + key + " value: " + table.get(key));
if (table.get(key) % 2 == 0) {
ans = "YES";
System.out.println("found even");
continue;
} else {
System.out.println("found odd");
if (isEven) {
ans = "NO";
break;
} else {
oddCounter++;
if (oddCounter > 1) {
ans = "NO";
break;
}
}
}
}
// Assign ans a value of s or no, depending on whether or not inputString satisfies the required condition
System.out.println(ans);
myScan.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment