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
perfect_noob's solution for 100: Most Used Character, written in Java
import java.util.HashSet; public class MostUsedCharacter { public String mostUsed(String sentence) { sentence =sentence.toLowerCase(); HashSet <Character> mapa = new HashSet <Character>(); String[] niz = sentence.split(" "); String t =""; String tt=""; String string = ""; for (int i=0;i<niz.length; i++){ for (int j=0; j<niz[i].length(); j++){ mapa.add(niz[i].charAt(j)); } for(char d:mapa){ t+=d; } mapa.clear(); string+=t; t = ""; } System.out.println(string); int max =0; int maxi=0; int[] br =new int[10000]; for (int i=0; i<string.length(); i++){ for (int j=i+1; j<string.length(); j++){ if (string.charAt(i)==string.charAt(j)) br[i]++; } System.out.println(br[i]); if (br[i]>max){ max=br[i]; maxi = i; } if(br[i]==max){ char d = string.charAt(i); char dd = string.charAt(maxi); if (d<dd){ max =br[i]; maxi = i; } } } tt += string.charAt(maxi); return tt; } }