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
aleksp's solution for 100: Most Used Character, written in Java
public class MostUsedCharacter { public static int count(String sen) { int p=0; int l=0; boolean ever=true; while (ever) { if (l==sen.length()) break; while (l<sen.length() && Character.isSpaceChar(sen.charAt(l++))); if (l==sen.length()) break; while (l<sen.length() && !Character.isSpaceChar(sen.charAt(l++))); if (l==sen.length()) return p+1; l--; p++; } return p; } public static String dajZbor(int n, String s) { int p=-1; int i=0; int l=0; boolean ever=true; while (ever) { while (l<s.length()&&Character.isSpaceChar(s.charAt(l++))); l--; p++; if (p==n) { int k=l; while (k<s.length()&&!Character.isSpaceChar(s.charAt(k))) k++; return s.substring(l, k); } else { while (l<s.length()&&!Character.isSpaceChar(s.charAt(l++))); } } return ""; } public static boolean sodrzi(String s, char c) { for (int i=0; i<s.length(); i++) if (s.charAt(i)==c) return true; return false; } public static String mostUsed(String sentence) { String words[]=new String[count(sentence)]; for (int j=0; j<words.length; j++) words[j]=dajZbor(j, sentence); int niza[]=new int[26]; int pos=0; int max=0; for (char c='a'; c<='z'; c++) { for (int i=0; i<words.length; i++) if (sodrzi(words[i], c)) { niza[pos]++; } pos++; } for (int i=0; i<26; i++) if (niza[i]>max) { max=niza[i]; pos=i; } return Character.toString((char)(pos+97)); } }