You are given two words (not necessarily meaningful words) over the lower case English alphabet. They are to be merged into a single new word in which all the letters (including repetitions) in the given two words occur in increasing order (‘a’ is the least and ‘z’ is the largest) from left to right.
Example : If the two words are “ehllo” and “wrold”, the output is “dehllloorw”.
Explanation : d, e, h , l, o, r, w is the increasing order among the distinct letters. Since all the letters must occur in the output word, the output is “dehllloorw”.
Input : Two words, one on each line.
Output : The merged word as described in the problem statement.
Constraints : 0 < length of each word <= 10.
#include<stdio.h>
Example : If the two words are “ehllo” and “wrold”, the output is “dehllloorw”.
Explanation : d, e, h , l, o, r, w is the increasing order among the distinct letters. Since all the letters must occur in the output word, the output is “dehllloorw”.
Input : Two words, one on each line.
Output : The merged word as described in the problem statement.
Constraints : 0 < length of each word <= 10.
#include<stdio.h>
#include<string.h>
int main()
{
char s1[20],s2[10],a;
int c,i,j,x[26]={0};
scanf("%s %s", s1,s2);
strcat(s1,s2);
for(i=0;i<26;i++)
{
c=s1[i];
c=c-97;
x[c]++;
}
for(i=0;i<26;i++)
{
while(x[i]>0)
{
j=i+97;
a=j;
printf("%c",a);
x[i]--;
}
}
return 0;
}
No comments:
Post a Comment