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
dsmilkov's solution for 100: Most Used Character, written in Java
public class MostUsedCharacter { public String mostUsed(String sentence) { String [] niza = sentence.split(" +"); int alfa[] = new int[26]; for (int i = 0; i < alfa.length; i++) { alfa[i] = 0; } for (int i = 0; i < niza.length; i++) { niza[i] = niza[i].toUpperCase(); for (int j = 65; j <= 90; j++) { char tmp = (char)j; String tmp2 = new String(""); tmp2+=tmp; if (niza[i].contains(tmp2)) alfa[j-65]++; } } int max = 0; int index = 25; for (int i = 0; i < alfa.length; i++) { if (alfa[i]>max) { max = alfa[i]; index = i; } } char tmp = (char)(index+65); String out = new String(""); out+=tmp; out = out.toLowerCase(); return out; } /*public static void main(String[] args) { MostUsedCharacter test = new MostUsedCharacter(); System.out.println(test.mostUsed("zaaa y abyce qweew oiwuer kjhqwe mbqmqwe kasd qweq werkqwerq wer qwer qwerq wer")); }*/ }