Assignment 5

 

You shall write a C++ program that:

  1. Reads an arbitrary number of whitespace-delimited tokens from standard input.
  2. Determines and prints (to standard output) two decimal integer values:
    1. The number of input tokens that are valid Scrabble words (case-insensitive), i.e. those that can be found in /srv/datasets/scrabble-hybrid.
    2. The total number of points that all those words would be worth in Scrabble, according to the letter values in /srv/datasets/scrabble-letter-values.

Specific Requirements

  1. You may assume that the number of valid words and the total number of points will not exceed the range of an unsigned 64-bit integer.
  2. Open and read the contents of each relevant data file exactly once.
  3. Make sure to use STL components that will avoid any gross inefficiencies (excessive computation and/or storage) in your program. Your program should at least be able to process each of the example inputs below in no more than 5 seconds, on our server.
  4. Print the two integer values in the order specified above, and make sure your output contains no other numeric decimal values. Otherwise, the format of output is up to you.

Sample Executable and Expected Output

A sample executable named cs19_scrabble_total is available on the server, which demonstrates expected behavior of your program, e.g.:

$ cs19_scrabble_total <<< 'spinnaker'
1 word worth 15 points

$ cs19_scrabble_total < /srv/datasets/many-english-words.txt
519135 words worth 7566688 points

$ cs19_scrabble_total < /srv/datasets/shakespeare-othello.txt
17531 words worth 105915 points

$ cs19_scrabble_total < /srv/datasets/king-james.txt
650865 words worth 4305807 points
Tags: No tags