単語の平均文字数による場合分けをして、点数を返す問題。
[java]
public class HowEasy {
public int pointVal(String problemStatement) {
String words[] = problemStatement.split(" ");
int noWord = 0;
int length = 0;
for(String word : words)
if( word.matches("^[a-zA-Z]+.*$"))
length += word.endsWith(".") ? word.length()-1 : word.length();
else
noWord++;
if (words.length-noWord == 0 || length / (words.length-noWord) <=3)
return 250;
else if ( length/(words.length-noWord) <=5)
return 500;
else
return 1000;
}
}
[/java]
0 件のコメント:
コメントを投稿