#R2025S0104. Similar String

Similar String

Similar String

时间限制:1000ms

空间限制:256MB

题目描述

给定 n 个字符串 words ,如果两个字符串由相同的字符构成,则认为它们是相似(Similar)的。

请你告诉Monster,有多少对相似字符串。

输入格式

输入 n+1 行。

第一行一个整数 n 表示将给出 n 个字符串。

接下来 n 行每行一个字符串 words[i]

输出格式

输出一个整数,代表相似字符串的对数。

样例输入1

5
aba
aabb
abcd
bac
aabc

样例输出1

2

样例1解释

”aba","aabb","abcd","bac","aabc"

共有 2 对满足条件:

i = 0 且 j = 1 :words[0] 和 words[1] 只由字符 'a' 和 'b' 组成。

i = 3 且 j = 4 :words[3] 和 words[4] 只由字符 'a'、'b' 和 'c' 。

样例输入2

3
aabb
ab
ba

样例输出2

3

样例2解释

"aabb","ab","ba"

共有 3 对满足条件:

i = 0 且 j = 1 :words[0] 和 words[1] 只由字符 'a' 和 'b' 组成。

i = 0 且 j = 2 :words[0] 和 words[2] 只由字符 'a' 和 'b' 组成。

i = 1 且 j = 2 :words[1] 和 words[2] 只由字符 'a' 和 'b' 组成。

数据范围及约定

对于 100%100\% 的数据,2n1002 \le n \le 1001<=words.length<=1001 <= words.length <= 1001<=words[i].length<=1001 <= words[i].length <= 100words[i] 仅由小写英文字母组成。