circumgyrate the string
Time Limit: 10000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6817 Accepted Submission(s): 1720
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2137
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
Source
HDU 2007-11 Programming Contest_WarmUp
Recommend
威士忌 | We have carefully selected several similar problems for you: 2133 2136 2134 2135 2131
PS:n可以是负数!
代码如下:
#include<stdio.h>
#include<string.h>
int zhengfu(int n)
{
if(n<0) return -n;
}
int main()
{
char s[81];
int n;
while(~scanf("%s %d",s,&n))
{
n=zhengfu(n);
int k=strlen(s)-1;
int L=0;
switch(n%8)
{
case 0:printf("%s\n",s);break;
case 4:
for(int i=strlen(s)-1;i>=0;i--)
printf("%c",s[i]);
printf("\n");
break;
case 1:
for(int i=strlen(s)-1;i>=0;i--)
{
for(int j=1;j<=k;j++)
printf(" ");
printf("%c\n",s[i]);
k--;
}
break;
case 5:
for(int i=0;i<strlen(s);i++)
{
for(int j=1;j<=k;j++)
printf(" ");
printf("%c\n",s[i]);
k--;
}
break;
case 2:
for(int i=strlen(s)-1;i>=0;i--)
{
for(int j=1;j<k/2+1;j++)
printf(" ");
printf("%c\n",s[i]);
}
break;
case 6:
for(int i=0;i<strlen(s);i++)
{
for(int j=1;j<k/2+1;j++)
printf(" ");
printf("%c\n",s[i]);
}
break;
case 3:
for(int i=strlen(s)-1;i>=0;i--)
{
for(int j=0;j<L;j++)
printf(" ");
printf("%c\n",s[i]);
L++;
}
break;
case 7:
for(int i=0;i<strlen(s);i++)
{
for(int j=0;j<L;j++)
printf(" ");
printf("%c\n",s[i]);
L++;
}
break;
}
// printf("\n");
}
return 0;
}