circumgyrate the string
Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4901 Accepted Submission(s): 1145
Problem Description
Give you a string, just circumgyrate. The number N means you just circumgyrate the string N times, and each time you circumgyrate the string for 45 degree anticlockwise.
Input
In each case there is string and a integer N. And the length of the string is always odd, so the center of the string will not be changed, and the string is always horizontal at the beginning. The length of the string will not exceed 80, so we can see the
complete result on the screen.
Output
For each case, print the circumgrated string.
Sample Input
asdfass 7
Sample Output
a s d f a s s
Author
wangye
注意n可以是负的。。。
#include<cstdio>
#include<iostream>
#include<cstring>
char s[1000];
void ok(int n);
using namespace std;
int main()
{
int m=0;
while(scanf("%s %d",s,&m)!=EOF)
{
while(m<0)
m+=8;
getchar();
ok(m%8);
}
return 0;
}
void ok(int n)
{
int k=strlen(s);
if(n==0)
printf("%s\n",s);
else if(n==1)
{
for(int i=k-1;i>=0;i--)
{
for(int j=0;j<i;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==2)
{
for(int i=k-1;i>=0;i--)
{
for(int j=0;j<k/2;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==3)
{
for(int i=k-1;i>=0;i--)
{
for(int j=0;j<k-1-i;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==4)
{
for(int i=k-1;i>=0;i--)
printf("%c",s[i]);
printf("\n");
}
else if(n==5)
{
for(int i=0;i<k;i++)
{
for(int j=0;j<k-1-i;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==6)
{
for(int i=0;i<k;i++)
{
for(int j=0;j<k/2;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==7)
{
for(int i=0;i<k;i++)
{
for(int j=0;j<i;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
}
#include<iostream>
#include<cstring>
char s[1000];
void ok(int n);
using namespace std;
int main()
{
int m=0;
while(scanf("%s %d",s,&m)!=EOF)
{
while(m<0)
m+=8;
getchar();
ok(m%8);
}
return 0;
}
void ok(int n)
{
int k=strlen(s);
if(n==0)
printf("%s\n",s);
else if(n==1)
{
for(int i=k-1;i>=0;i--)
{
for(int j=0;j<i;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==2)
{
for(int i=k-1;i>=0;i--)
{
for(int j=0;j<k/2;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==3)
{
for(int i=k-1;i>=0;i--)
{
for(int j=0;j<k-1-i;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==4)
{
for(int i=k-1;i>=0;i--)
printf("%c",s[i]);
printf("\n");
}
else if(n==5)
{
for(int i=0;i<k;i++)
{
for(int j=0;j<k-1-i;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==6)
{
for(int i=0;i<k;i++)
{
for(int j=0;j<k/2;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
else if(n==7)
{
for(int i=0;i<k;i++)
{
for(int j=0;j<i;j++)
printf(" ");
printf("%c\n",s[i]);
}
}
}