DMOPC '15 Contest 7 P2 - Not a Wall of Text

View as PDF

Submit solution

Points: 3 (partial)
Time limit: 2.0s
Memory limit: 64M

Problem type

After seeing the first problem, you are probably very angry at the fact that you wasted a lot of time reading. For this problem, you should just count the number of words you have to read in a text. That's it. No tricks, no hidden catches. For the purposes of this problem, a word is any maximal contiguous group of non-whitespace characters.

Input Specification

The input will be a text with only lowercase letters and spaces (ASCII code 32). You should count how many words there are. The only constraint is that the length of the entire text will not exceed 80 characters (because nobody likes essays). Also, there won't be anything tricky like double whitespace in a row, leading whitespace, or trailing whitespace because we don't roll like that. In fact, we won't even give you a trailing newline to deal with.

Output Specification

Output the number of words in the text.

Sample Input

problem one is really long

Sample Output



  • 0
    thodges314  commented on Dec. 28, 2021, 2:26 a.m.

    Also, I am here from Zingaro's book. A bit concerning that this doesn't account for the condition of multiple spaces separating words. I'm assuming methods to split a string into an array of strings comes later.

    • 0
      TShark62  commented on Jan. 9, 2022, 10:24 p.m.

      Please read the Input Specification above...

  • 0
    PerryCodes  commented on Oct. 20, 2021, 4:52 p.m. edited

    Is paydayzcool comment a reference to how simple it is?

  • 3
    PerryCodes  commented on Oct. 10, 2021, 6:56 p.m.

    Problem #1: Word Count from "Learn to Code by Solving Problems A Python Programming Primer" by Daniel Zingaro.

    Pretty good book so far. Let's hope it doesn't piddle out!

  • 3
    codeHH698  commented on July 28, 2021, 4:38 p.m.

    Don't read the text, just read the output specification

  • 4
    paydayzcool  commented on Dec. 14, 2016, 11:06 a.m.

    Lol I nearly thought this was a CCCJQR question