Caveman Number Count

Run Settings
LanguageJava
Language Version
Run Command
import java.util.*; class Caveman { static String[] wordNumberList = { "ook", "ookook", "oog", "ooga", "ug", "mook", "mookmook", "oogam", "oogum", "ugug" }; public static void main(String[] args) { Scanner scan = new Scanner(System.in); while (scan.hasNext()) { String s = scan.nextLine(); System.out.println(String.format("%s => %d", s, countNeanderthalWords(s))); } scan.close(); } public static int countNeanderthalWords(String line) { if (line.length() == 0) return 1; int counter = 0; for (String wordNumber : wordNumberList) { if (line.startsWith(wordNumber)) { counter += countNeanderthalWords(line.substring(wordNumber.length())); } } return counter; } }
Editor Settings
Theme
Key bindings
Full width
Lines