Consonant Reversal solution

Ritika gives N strings to Semona and asks her to perform a consonant reversal on each string S such that the indexed positions of its vowels (ae , io, and u) are unchanged but all the consonants are reversed. This means that each vowel must be at the same exact index before and after the reversal. Because the value of N is very large, Semona wants your help accomplishing this with code!
Given N strings, reverse and print each string such that the positions of its vowels remain unchanged but all its consonants are reversed.
Input Format
The first line contains an integer, N, the number of strings.
Each of the N subsequent lines contains a string, S, to be reversed.
Constraints
  • 1N1000
  • 1|Si|2000, where 0i<N
  • Each string contains lowercase letters.
Output Format
For each string S received as input, print the consonant reversal of S on a new line.
Sample Input
2
abcde
eabafgs
Sample Output
adcbe
easagfb
Explanation
N=2
S0="abcde"
This string has 2 vowels that must stay in place: the a at index 0 and the e at index 4. We reverse only the consonants (leaving the vowels in place), and print the result (adcbe) on a new line.
S1="eabafgs"
This string has 3 vowels that must stay in place (at indices 01, and 3). We reverse only the consonants (leaving the vowels in place), and print the result (easagfb) on a new line.

#include <stdio.h>
#include <string.h>


int main()
{
        int n,i,j,l,k;
        char str[50],tmp[50],t;
        
    scanf("%d",&n);
    for(k=0;k<n;k++)
        {
          scanf("%s",&str);
       
            l=strlen(str);
        
        
            for(j=l-1,i=0;j>=0;)
          {
                    if(str[j]=='a'||str[j]=='e'||str[j]=='i'||str[j]=='o'||str[j]=='u'||str[j]=='A'||str[j]=='E'||str[j]=='I'||str[j]=='O'||str[j]==
                       'U')
                        {
                        tmp[j]=str[j];
                j--;
                
            } 
                else
                    
                    if(str[i]=='a'||str[i]=='i'||str[i]=='e'||str[i]=='o'||str[i]=='u'||str[i]=='A'||str[i]=='E'||str[i]=='I'||str[i]=='O'||str[i]=='U'){
                      
                       tmp[i]=str[i];
                    i++;
                }
                    else
                        {
                               t=str[i];
                    
                                         tmp[i]=str[j];
                        fflush(stdin);
                            str[j]=t;
                        i++;
                        j--;
                        
                    }
            }
        
               tmp[l]='\0';
                               printf("%s",tmp);
            
        printf("\n");
    }
    

    return 0;
}

Comments

Popular posts from this blog

Pre-compiled Headers

CONNECTING WITH FTP-FILE TRANSFER PROTOCOL

PROBING THE INTERNET WITH TELNET: