#C11302. Count Common Words

    ID: 40604 Type: Default 1000ms 256MiB

Count Common Words

Count Common Words

Given two strings representing documents, your task is to count the number of unique common words between them. A word is defined as a sequence of non-space characters, and words are case-sensitive.

Mathematically, if we denote the set of words in document 1 as \( S_1 \) and in document 2 as \( S_2 \), then the answer is given by:

\( |S_1 \cap S_2| \)

For example, if the input is:

apple banana cherry
banana fruit cherry

then the output is 2 because "banana" and "cherry" are common to both documents.

inputFormat

The input consists of exactly two lines. The first line contains the first document and the second line contains the second document. Each document is a string of words separated by spaces.

outputFormat

Output a single integer representing the number of unique common words between the two documents.## sample

apple banana cherry
dog cat mouse
0