Sunday, July 27, 2008
C challenge
You are given any character string. Find the number of sets of vowels that come in the order of aeiou in the given string. For eg., let the given string be DIPLOMATIC. The answer returned must be "The number of sets is 2" and "The sets are "IO and AI". Vowels that form a singleton set must be neglected. Try to post the program executable in gcc or g++ or in java.
Subscribe to:
Post Comments (Atom)
2 comments:
int check(char ch)
{
int i;
char a[5]={'a','e','i','o','u'};
for(i=0;i<5;i++)
if(ch==a[i])
return 1;
if(i==5)
return 0;
}
int main()
{
char str[15],a[15];
int k=0,i;
scanf("%s",str);
for(i=0;str[i];i++)
{
if(check(str[i]))
{
if(k>0)
{
if(a[k-1]<=str[i])
a[k++]=str[i];
else
{
a[k]='\0';
printf("%s\n",a);
k=0;
a[k++]=str[i];
}
}
else
a[k++]=str[i];
}
}
a[k]='\0';
printf("%s\n",a);
}
int main()
{
char str[50],ch1='a';
int i,j=0,count=0;
printf("\nEnter the string : ");
scanf("%s",str);
getchar();
for(i=0;str[i];i++)
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
{
if(ch1<=str[i])
{
ch1=str[i];
j++;
}
else
{
if(j>=2)
count++;
j=1;
ch1=str[i];
}
}
}
if(j>=2)
count++;
printf("\nNo of ordered sets is %d",count);
return 0;
}
Post a Comment