Posts

Search

I M11 - Special Chemical Element

Toyland unlike Earth has only 26 chemical elements known as of now. Each element is identified as a lowercase English letter in range ‘a’ - ‘z’. Every chemical compound is composed of these given chemical elements only. A chemical element is special if it is present in all the given compounds.
You are given a list of N chemical compounds. Print the number of special chemical elements.
Input Format
First line represent the integer N, number of chemical compounds. Next N lines contains chemical composition of each of the compound, consisting of lowercase english letter (‘a’ - ‘z’).
Constraints
1 ≤ N ≤ 100 1 ≤ length of composition of chemical compound ≤ 100
Output Format
Print the number of special chemical elements
Sample Input 0
4
abbbc
xbady
bghla 
aba
Sample Output 0
2
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<map>
using namespace std;
int main()
{
map<char,int>ml;
int cn=0;
string str;
int t;
cin>>t;
for(int i=0;i<t;i++)
{
    cin>>str;
    for(int j=0;j<str.length();j++)
    {
        char ch=str[j];
        if(ml[ch]==i)
            ml[ch]++;
    }
}
map<char,int>::iterator itr;
for(itr=ml.begin();itr!=ml.end();itr++)
{
    if(itr->second==t)
        cn++;
}
cout<<cn;
return 0;
}