SRM290Div2,250

この記事は約3分で読めます。

Johnny wants to become a great programmer, so he practices to improve his programming skills all the time. He thinks he can save a lot of time if he can learn to type faster. It’s said that the key to speed typing is keeping the rhythm, which means pressing each key after a constant interval of time. Johnny, like many programmers, loves all kinds of statistics, so he created a program for measuring his typing progress. The program receives a String letters and a int[] times, representing the keys he pressed and the time of each press in milliseconds respectively. The ith element of times is the time at which he typed the ith character in letters. No key is pressed more than once, and all the times are relative to the start of his practice session.

For this problem you may assume that the average time of one key press will be an integer.

Your task is to calculate which letters take Johnny more than average time to type, so he can practice those letters more. Return a String containing all such letters in the order that they occur in the input.
[java]
public class SpeedTyper {
public String lettersToPractice(String letters, int[] times) {
int ave=0;
String ans="";
int buff=0;
for (int i = 0; i < times.length; i++) {
ave+=times[i]-buff;
buff=times[i];
}
ave/=times.length;
buff=0;
for (int i = 0; i < letters.length(); i++) {
System.out.println(ave+":"+(times[i]-buff));
if(ave<(times[i]-buff)){
ans+=letters.substring(i,i+1);
}
buff=times[i];
}
return ans;
}
}
[/java]

コメント

タイトルとURLをコピーしました