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
BojanKostadinov's solution for 100: Most Used Character, written in Java
public class MostUsedCharacter { public String mostUsed(String sentence) { String n = sentence.toLowerCase(); while (n.contains(" ")) n = n.replaceAll(" ", " "); if (n.charAt(0) == ' ') n = n.substring(1); if (n.charAt(n.length()-1) == ' ') n = n.substring(0, n.length()-1); String[] p = n.split(" "); int count = 0, maxcount = -1; String ret = ""; String zz = " "; for (char zzz = 'a'; zzz<='z'; zzz++) { count = 0; zz = zz.replace(' ', zzz); //String zx= new String(zz); for (int m=0; m<p.length; m++) if (p[m].contains(zz)) count++; if (count > maxcount) { ret = new String(zz); maxcount = count; } zz = zz.replace(zzz, ' '); } return ret; } }