Tuesday, 23 September 2014

Hackerrank Gem Stones Solution

The Solution for hackerrank problem, Gem Stones using C Program.
Passed Test cases: 27 out of 27

SOURCE CODE:

 #include<stdio.h>  
 int main()  
   {  
   int n,a[26]={0},flag=1,k,count=0;  
   scanf("%d",&n);  
   while(n--){  
     char al[100];  
     int b[26]={0},i,j;  
     scanf("%s",al);  
     for(i=0;al[i]!='\0';i++){  
       int num = al[i]-97;  
       b[num]=1;  
     }  
       if(flag==1){  
         for(j=0;j<26;j++){  
           a[j]=b[j];  
         
         }  
         flag=0;  
       }else{  
         for(j=0;j<26;j++){  
           a[j] = a[j]&b[j];  
         
         }  
       }  
   }  
   for(k=0;k<26;k++){  
     if(a[k]==1){  
       count++;  
     }  
   }  
   printf("%d\n",count);  
   return 0;  
 }  


0 comments:

Post a comment