C Programming – HackerRank Solution | Reverse Words 11 |

(HackerRank) Write a Modular C Programming code to solve Reverse Words 11, Given a String S, reverse the string without reversing its individual words. Words are separated by dots.

Given a String S, reverse the string without reversing its individual words. Words are separated by dots.

Input Format

First line contains a string separated by dot between individual words.

Constraints

1 <= |S| <= 2000

Output Format

Display the output string in one line

Sample Input 0

i.like.this.program.very.much

Sample Output 0

much.very.program.this.like.i

Explanation 0

Take each word from the end and add the same to the string at the beginning. Note that each word is separated by a dot.

Refer : C Programming HackerRank all solutions for Loops | Arrays | strings | Data Structures | Linked lists | Stacks | Queues | Binary Trees

 

CODE:

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

int main() {
    char str[100],temp;
    scanf("%s",str);
    int dots=0,i,j,s,l;
    l=strlen(str);
    for(i=0;i<l/2;i++)
    {
        temp=str[i];
        str[i]=str[l-1-i];
        str[l-1-i]=temp;
    }
   // printf("%s\n",str);
    i=0;
    while(str[i])
    {
        if(str[i]==46)
            dots++;
        i++;
    }
    s=0;
    for(j=0;j<dots;j++)
    {
        i=s;
        while(str[i]!=46)
        {
            i++;
        }
        l=i;
        for(i=0;i<((l-s)/2);i++)
        {
        temp=str[s+i];
        str[s+i]=str[l-1-i];
        str[l-1-i]=temp;
        }
        s=l+1;
    }
    l=strlen(str);
        for(i=0;i<(l-s)/2;i++)
        {
        temp=str[s+i];
        str[s+i]=str[l-1-i];
        str[l-1-i]=temp;
        }
    printf("%s",str);
    return 0;
}

OUTPUT

Congratulations, you passed the sample test case.

Click the Submit Code button to run your code against all the test cases.

Input (stdin)

i.like.this.program.very.much
Your Output (stdout)

much.very.program.this.like.i
Expected Output

much.very.program.this.like.i

 

Please find some more codes of Loops, Condition Statements, 1D Arrays, 2D Arrays, Strings, Pointers, Data Structures, Files, Linked lists, Stacks, Queues, Binary Trees, MISC, Solved model question papers & Hacker Rank all solutions on the below page:

Top 100+ C Programming codes – KLE Technological University

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

Welcome to FactsPrime

Sorry, We have detected that you have activated Ad-Blocker. Please Consider supporting us by disabling your Ad Blocker, It helps us in maintaining this website. To View the content, Please disable adblocker and refresh the page.

Thank You !!!