Register
|
Login
Home
News
Competitions
Practice
How to
Rankings
Calendar
Arena
CodeFu 2007
CodeFu'07 Highlights
Jazoon'07 Highlights
Schedule
Rules
Prizes
Results
Competitions
»
Main CodeFu Competitons
»
CodeFu 2007
»
Results
CodeFu 2007 Results
CodeFu Final Round Results
cyb3rc0re's solution for 100: Most Used Character, written in Java
import java.util.*; public class MostUsedCharacter { public static String mostUsed(String sentence) { String letters = "abcdefghijklmnopqrstuvwxyz"; ArrayList repeating = new ArrayList(); String[] word = sentence.split(" "); if(word.length == 1){ TreeMap tm = new TreeMap(); for(int j=0;j<sentence.length();j++){ tm.put(sentence.charAt(j), 0); } System.out.println(tm.toString()); return tm.firstKey().toString(); } else { for(int i=0;i<word.length;i++){ TreeMap tm = new TreeMap(); tm.clear(); for(int j=0;j<word[i].length();j++){ tm.put(word[i].charAt(j), i); } System.out.println(word[i]+" "+tm.toString()); for(int k=0;k<letters.length();k++){ if(tm.containsKey(letters.charAt(k))){ repeating.add(letters.charAt(k)); } } } return count(repeating); } //return ""; } public static String count(ArrayList al){ int counter = 1; String letter = al.get(0).toString(); for(int j=0;j<al.size(); j++){ int c = 1; for(int i=0;i<al.size();i++){ if(i!=j){ if(al.get(j) == al.get(i)){ c++; } } } if(c>counter){ letter = al.get(j).toString(); counter = c; }else if(c==counter){ if(letter.compareTo(al.get(j).toString()) > 0){ letter = al.get(j).toString(); counter = c; } } } //System.out.println(al.toString()); return letter; } }