top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Write a program to find common alphabet in all the strings.

+6 votes
2,761 views

Take input 'n' as number of strings and find the common alphabet among them.
For example:
Input:

Number of Strings - 3
List of Strings - 
abcdde
baccd
eeabg

output:

2   

as 'a' and 'b' are only two common alphabet among those three strings

posted Mar 25, 2016 by Shahsikant Dwivedi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

I wrote a program assuming characters of all strings will be either smallcase or capitalcase. Please find the same as below:

void IndexMap(char *);
int  output[26] = {0};
int main ()
{
   int n;
   int indx;
   char string[n][255];
   printf ("How many strings want to enter");
   scanf("%d", &n);
   /* Find common characters from all the entered stings */
   for (indx = 0; indx < n; indx++)
   {
      printf("Enter %d string\n", indx+1);
      scanf("%s", string[indx]);
      IndexMap(string[indx]);
   }
   for (indx = 0; indx < 26; indx++)
   {
      if (output[indx] == n)
      printf("Common character [%c] from all strings\n", 'a'+ indx);
   }
   return 0;
}
void IndexMap(char *string)
{
   while (*string != '\0')
   output[*string++ - 'a']++;
}

If any has better algorithm or program, please share.

answer Mar 26, 2016 by Vikram Singh
not getting the desired output.check out your output :https://ideone.com/8EaB1D
your program will get the output 5 instead of 2 as it will increment the output array for charecters 'c','d'  and 'e' also...since they are repeating in the string;
Similar Questions
+5 votes

Take a string as an input and identify whether it is Pangram or not. Pangrams are those sentences,which is constructed by using all letters of the alphabet at least once.

+2 votes

Given a set of random strings, write a function that returns a set that groups all the anagrams together.

Ex: star, dog, car, rats, arc - > {(star, rats), (arc,car), dog}

+2 votes

Write a C program which accept two strings and print characters in second string which are not present in first string?

Example:
String 1: apple
String 2: aeroplane

output:
ron

...