Timed Reading

Description:

Timed Reading is an educational tool used in many schools to improve and advance reading skills. A young elementary student has just finished his very first timed reading exercise. Unfortunately he’s not a very good reader yet, so whenever he encountered a word longer than maxLength, he simply skipped it and read on.

Help the teacher figure out how many words the boy has read by calculating the number of words in the text he has read, no longer than maxLength.
Formally, a word is a substring consisting of English letters, such that characters to the left of the leftmost letter and to the right of the rightmost letter are not letters.

Example

For maxLength = 4 and
text = "The Fox asked the stork, 'How is the soup?'",
the output should be
timedReading(maxLength, text) = 7.

The boy has read the following words: "The", "Fox", "the", "How", "is", "the", "soup".

Input/Output

  • [time limit] 3000ms (cs)
  • [input] integer maxLength

    A positive integer, the maximum length of the word the boy can read.

    Constraints:
    1 ≤ maxLength ≤ 10.

  • [input] string text

    A non-empty string of English letters and punctuation marks.

    Constraints:
    3 ≤ text.length ≤ 110.

  • [output] integer

    The number of words the boy has read.

Tests:
Solutions:

int timedReading(int maxLength, string text) {
    string[] words = text.Split(' ');
    int count=0;
    if(words.Length==0)
        words[0]=text;
    foreach(string word in words) {
        Regex r = new Regex("(?:[^a-zA-Z ]|(?<=[.'\"])s)", 
            RegexOptions.IgnoreCase | 
            RegexOptions.CultureInvariant |
            RegexOptions.Compiled);
        string trimmedWord =r.Replace(word, String.Empty);
        
        if(trimmedWord.Length<=maxLength && trimmedWord.Length>0)
            count++;
    }
    return count;
}

Advertisements

One thought on “Timed Reading

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s