50026. A Better Word Count

I'm a slow walker, but I never walk backwards.

Problem Description

Given the name of a file, count the numbers of lines, words, and bytes in it. A line is a sequence of characters that end with a new line '\n' or EOF. For example, if a file has "abc\n9 9 " then it has two lines -- "9 9 " is also a line since it ends with EOF. Another way to see it is that a line ends with '\n'. However, if a file does not end with '\n' and there exists at least one character between EOF and the last '\n', then that is also a line. A line will not have more than 1024 characters (including the optional new line character).

A word is a sequence of letters. For example if a file has "abc+def hhh\n" then it has three words. A word will not have more than 1024 characters.

Subtasks

  • 5pt. The file has nothing.
  • 10pt. The file has only letters.
  • 10pt. The file has only letters and ends with a new line ('\n').
  • 20pt. The file has only letters at the beginning and ends with a sequence of new lines ('\n's).
  • 30pt. The file has letters, space, and newlines.
  • 25pt. The file could have anything.

Sample Input 1 (stdin)

p10064-shibai.dat

Sample Output 1 (stdout)

4 44 225

Sample Input 2 (stdin)

p10064-tmp.dat

Sample Output 2 (stdout)

1 1 3

Hint

You are free to open the file for multiple times if you wish.

donwload p50026-shibai.dat, p50026-tmp.dat

morris@morris-PC MINGW64 ~/Desktop
$ cat p50026-shibai.dat
Anybody should be fine if it was just to ease loneliness
Because the stars in the night sky seems like falling, I cant lie to myself
One more time, please dont' change the season
One more time to the time when we fool around
 
morris@morris-PC MINGW64 ~/Desktop
$ xxd p50026-shibai.dat
00000000: 416e 7962 6f64 7920 7368 6f75 6c64 2062  Anybody should b
00000010: 6520 6669 6e65 2069 6620 6974 2077 6173  e fine if it was
00000020: 206a 7573 7420 746f 2065 6173 6520 6c6f   just to ease lo
00000030: 6e65 6c69 6e65 7373 0a42 6563 6175 7365  neliness.Because
00000040: 2074 6865 2073 7461 7273 2069 6e20 7468   the stars in th
00000050: 6520 6e69 6768 7420 736b 7920 7365 656d  e night sky seem
00000060: 7320 6c69 6b65 2066 616c 6c69 6e67 2c20  s like falling,
00000070: 4920 6361 6e74 206c 6965 2074 6f20 6d79  I cant lie to my
00000080: 7365 6c66 0a4f 6e65 206d 6f72 6520 7469  self.One more ti
00000090: 6d65 2c20 706c 6561 7365 2064 6f6e 7427  me, please dont'
000000a0: 2063 6861 6e67 6520 7468 6520 7365 6173   change the seas
000000b0: 6f6e 0a4f 6e65 206d 6f72 6520 7469 6d65  on.One more time
000000c0: 2074 6f20 7468 6520 7469 6d65 2077 6865   to the time whe
000000d0: 6e20 7765 2066 6f6f 6c20 6172 6f75 6e64  n we fool around
000000e0: 0a                                       .

Discussion