#C183. Jaccard Similarity of Word Sets

    ID: 45078 Type: Default 1000ms 256MiB

Jaccard Similarity of Word Sets

Jaccard Similarity of Word Sets

Given two strings, calculate the Jaccard Similarity of the sets of words obtained from them. The Jaccard Similarity \(J\) is defined as:

[ J(A,B) = \frac{|A \cap B|}{|A \cup B|} ]

where \(A\) and \(B\) are the sets of words extracted from the two strings after removing punctuation and converting all letters to lowercase. If both strings contain no valid words, the similarity is defined as 1.0.

The input consists of two lines, each containing a string. Your task is to compute the similarity and print it as a floating-point number to stdout.

inputFormat

The input consists of two lines:

  • The first line is the first string.
  • The second line is the second string.

Each string may contain letters, digits, spaces, and punctuation.

outputFormat

Output a single floating-point number representing the Jaccard Similarity. The result should be printed to standard output.

## sample
I love programming
I love programming
1.0