#C9579. Count Unique Words
Count Unique Words
Count Unique Words
You are given a text document and your task is to compute the total number of unique words in the text. A word is defined as any sequence of characters that are separated by spaces. When counting, words are considered case-insensitive. For example, Hello
, hello
, and HELLO
are all treated as the same word.
The extraction of words is performed by matching the regular expression pattern \(\texttt{\\b\\w+\\b}\). That is, only sequences of alphanumeric characters (and underscore) are counted as words.
For instance, given the input:
Hello world! Hello again, world.
The unique words after converting to lowercase are "hello", "world", and "again", so the correct output would be 3.
inputFormat
The input is provided via standard input (stdin) and may consist of one or more lines of text. You should process the entire input as a single text document.
outputFormat
Output a single integer to standard output (stdout), representing the number of unique words in the input text.
## sampleHello world! Hello again, world.
3