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
bokic's solution for 100: Most Used Character, written in Java
public class MostUsedCharacter { public String mostUsed(String sentence) { String letters = ""; int[] lettercount = new int[sentence.length()]; int[] letterLastWord = new int[sentence.length()]; int currentWord = 1; int currentpos = 0; for(int c = 0; c < sentence.length(); c++) { char currentChar = sentence.charAt(c); if (currentChar == ' ') { currentWord++; continue; } int pos = letters.indexOf(currentChar); if (pos == -1) { pos = currentpos; letters += currentChar; currentpos++; }; if (letterLastWord[pos] == currentWord) continue; letterLastWord[pos] = currentWord; lettercount[pos]++; } int maxCount = 1; char charMaxCount = letters.charAt(0); for (int c = 0; c < lettercount.length; c++) { if ((lettercount[c] > maxCount)||((lettercount[c] == maxCount)&&(letters.charAt(c) < charMaxCount))) { maxCount = lettercount[c]; charMaxCount = letters.charAt(c); } } return String.valueOf(charMaxCount); } }