#K48202. Count Distinct Words

    ID: 28368 Type: Default 1000ms 256MiB

Count Distinct Words

Count Distinct Words

You are given a string s consisting of words separated by spaces. Your task is to count the number of distinct words in the string. Two words are considered the same if they exactly match.

Formally, if the set of words is \( S = \{w_1, w_2, \dots, w_n\} \), you need to output \(|S|\) (the number of distinct words).

For example, given the input "hello world", the output is 2. Given the input "repeat repeat repeat", the output is 1.

inputFormat

The input consists of a single line containing a string s which may include multiple words separated by spaces. Note that extra spaces may appear between words or at the beginning/end of the string.

outputFormat

Output a single integer representing the number of distinct words in the given string.## sample

hello world
2