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
TosheX's solution for 100: Most Used Character, written in Java
import java.util.StringTokenizer; public class MostUsedCharacter { public boolean contain (char ch, String s){ for (int i=0; i<s.length(); i++) if (ch==s.charAt(i)) return true; return false; } public String mostUsed(String sentence) { StringTokenizer recenica = new StringTokenizer(sentence); int[] count = new int['z'-'a'+1]; char tmp; String tmps = ""; String tekken; int mused=0; int times=0; for (int i=0; i<'z'-'a'; i++) count[i]=0; while (recenica.hasMoreTokens()){ tekken = recenica.nextToken(); for (int j=0; j<tekken.length(); j++){ tmp=tekken.charAt(j); if (!(contain(tmp, tmps))){ tmps+=tmp; count[tmp-'a']++; } } tmps=""; } for (int i=0; i<'z'-'a'; i++) if (count[i]>times){ times=count[i]; mused=i; } char r = (char)(mused+'a'); String p = ""; p+=r; return p; } }