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
vikjo's solution for 100: Most Used Character, written in Java
public class MostUsedCharacter { String alpha="abcdefghijklmnopqrstuvwxyz"; int [] cha; public String mostUsed(String sentence) { if(sentence.length() > 1000 || sentence.length() < 1) return ""; cha = new int[26]; for(int j =0; j<26; j++) cha[j] = 0; String sr = sentence; String[] ss = sr.trim().split(" "); for(int i =0; true; i++){ try { proveri(ss[i]); } catch(ArrayIndexOutOfBoundsException ex){break;} } return String.valueOf(alpha.charAt(max())); } private void proveri(String s){ if(s.intern() == "".intern()) return; for(int j =0; j<26; j++) { if(s.contains(String.valueOf(alpha.charAt(j)))) cha[j]++; s = s.replace(alpha.charAt(j), '0'); } // System.out.print(s+"/**/"); } private int max() { int max = 0, ind=0; for(int j =0; j<26; j++) if(cha[j]>max){ ind=j; max = cha[j];} return ind; } }