Pages

Thursday, December 31, 2009

TopCoder: HowEasy

public class HowEasy {
public int pointVal(String param0) {
String[] param = param0.split(" ");
int total = 0;
int divisor = 0;
for (int i = 0; i < param.length; i++) {
String word = param[i];

boolean flag = true;
for (int j = 0; j < word.length(); j++) {
if (!Character.isLetter(word.charAt(j))) {
if (word.charAt(j) == '.' && (j == word.length())) {
continue;
}
flag = false;
break;
}
}
if (flag) {
total += word.length();
divisor++;
}

}
int average = divisor == 0 ? 0 : total / divisor;
if (average <= 3) {
return 250;
} else if (average > 3 && average <= 5) {
return 500;
} else if (average >= 6) {
return 1000;
}
return 0;
}
}

No comments :