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
toroman's solution for 100: Most Used Character, written in Java
import java.util.Arrays; public class MostUsedCharacter { public String mostUsed(String sentence) { int a = 'a'; int z = 'z'; int[] count = new int[z+1]; boolean[] used = new boolean[z + 1]; for (String s: sentence.split(" +")) { Arrays.fill(used, false); for (int i=0; i<s.length(); i++) used[s.charAt(i)] = true; for (int i=a; i<=z; i++) if (used[i]) count[i]++; } int maxv = -1; int maxi = -1; for( int i=a; i<=z ;i++) if (count[i] > maxv) { maxv = count[i]; maxi = i; } String r = new String(new char[]{(char)maxi}); return r; } }