#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;
}
0 comments:
Post a Comment