UVA-11192 Group Reverse

 UVA-11192 (USING REVERSE FUNCTION OF C++ STL)

#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main()
{
    char s[200];
    int a,i,l,n,k,m;
    while(scanf("%d",&a)==1)
    {
        if(a==0)
        {
            break;
        }
        scanf("%s",s);
        n=strlen(s);
        l=n/a;
        for(i=1;i<=a;i++)
        {
            k=l*i;
            reverse(s+(k-l),s+(k));   // reverse(first length, last length), Here everytime difference 6

        }
        puts(s);


    }
    return 0;
}


WITHOUT REVERSE FUNCTION

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char s[1000];
    int a,i,j,k,l,n;
    while(scanf("%d",&a)==1)
    {

    if(a==0)
    {
        break;
    }
    scanf("%s",s);  // gets(s) is creating space problem
    k=strlen(s);
    l=k/a;
    for(i=1;i<=a;i++)
    {

        n=l*i;
       for(j=n-1;j>=n-l;j--)
       {
          printf("%c",s[j]);
       }



    }
     printf("\n");

    }
    return 0;



}

Download Coding Interview Book and Get More Tutorials for Coding and Interview Solution: Click Here

Download System Design Interview Book and Get More Tutorials and Interview Solution: Click Here

Do you need more Guidance or Help? Then Book 1:1 Quick Call with Me: Click Here

Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment