IITKWPCH - Find Number Of Pair of Friends
You are given n numbers. Any two number are called friends if they have some digit common. eg. (11, 12) and (15, 4561) are friends but (33, 556) is not.
Find out the number of pairs which are friends.
(Formally speaking let us suppose the n numbers are stored in array a[]. You have to find out number of i and j pairs such that i < j and a[i] and a[j] are friends.)
Input
T : no of test cases (T >= 1 && T <= 7)
For each test case, you will be given two lines, first line will contain n <= 10^6
then in next n line each line will contain a single integer representing a[i] (a[i] >= 1 && a[i] <= 10^18)
Output
For every test case print a line containing number of such pairs as mentioned in the problem statement.
Example
Input: 4 2 12 13 3 10 12 24 3 5 6 7 4 10 11 211 3 Output: 1 2 0 3
hide comments
Hitman:
2013-09-11 07:05:33
Learnt something new |
|
P_Quantum:
2013-09-11 07:05:33
Nice Question... :) |
Added by: | praveen123 |
Date: | 2013-08-05 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | general problem |