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
bobi4597's solution for 100: Most Used Character, written in Java
import java.util.*; public class MostUsedCharacter { public String mostUsed(String sentence) { int[] a = new int[26]; int[] b = new int[26]; for(int i = 0; i < 26; ++i) a[i] = 0; StringTokenizer st = new StringTokenizer(sentence); // if there are zero words, // then all leters have zero ocurences, "a" is first alphabeticaly if(!st.hasMoreTokens()) return "a"; while(st.hasMoreTokens()) { for(int j = 0; j < 26; ++j) b[j] = 0; String t = st.nextToken(); for(int i = 0; i < t.length(); ++i) { b[t.charAt(i)-'a'] = 1; } for(int j = 0; j < 26; ++j) a[j] += b[j]; } int maxTimes = 0; String s = ""; for(int i = 0; i < 26; ++i) { if(a[i] > maxTimes) { maxTimes = a[i]; s = ""+((char)((int)'a' + i)); } } return s; } }