## Gem Stones

John has discovered various rocks. Each rock is composed of various elements, and each element is represented by a lowercase latin letter from ‘a’ to ‘z’. An element can be present multiple times in a rock. An element is called a ‘gem-element’ if it occurs at least once in each of the rocks.

Given the list of rocks with their compositions, you have to print how many different kinds of gem-elements he has.

Input Format
The first line consists of N, the number of rocks.
Each of the next N lines contain rocks’ composition. Each composition consists of small alphabets of English language.

Output Format
Print the number of different kinds of gem-elements he has.

Constraints
1 ≤ N ≤ 100
Each composition consists of only small latin letters (‘a’-‘z’).
1 ≤ Length of each composition ≤ 100

Sample Input

``````3
abcdde
baccd
eeabg
``````

Sample Output

``````2
``````

Explanation
Only “a”, “b” are the two kind of gem-elements, since these characters occur in each of the rocks’ composition.

Hint (Java code)

import java.util.Scanner;

public class Solution {
private static String[] strings;
private static int N;
private static Scanner input;
private static char[] alphabet = {‘a’,’b’,’c’,’d’,’e’,’f’,’g’,’h’,’i’,’j’,’k’,’l’,’m’,’n’
,’o’,’p’,’q’,’r’,’s’,’t’,’u’,’v’,’w’,’x’,’y’,’z’};
private static int countGemElement = 0;

public static void main(String[] args){
input = new Scanner(System.in);
N = input.nextInt();
strings = new String[N];
for(int count = 1; count <= N; ++count)
strings[count-1] = input.next();
for(int count = 0; count < alphabet.length; ++count){
int countSame = 0;
for(int count1 = 0; count1 < strings.length; ++count1){
if(strings[count1].contains(String.format(“%s”, alphabet[count])))
countSame++;
}
if(countSame == N)
countGemElement++;
}
System.out.println(countGemElement);
}
}

Advertisements