HDU 2137 circumgyrate the string

来源:互联网 发布:小米4支持什么网络制式 编辑:程序博客网 时间:2024/06/05 15:46

circumgyrate the string

Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2583    Accepted Submission(s): 562


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
 

题意:就是旋转字符串。周期是8。注意正负。

AC代码:

#include <cstdio>#include <cstring>int main(){    char str[80];    int n;    while(scanf("%s%d",str,&n)!=EOF)    {        int len=strlen(str);        for(int i=0;i<len;i++)        {            if(n%8==0)            {                putchar(str[i]);                if(i==len-1) putchar('\n');            }            else if(n%8==1||n%8==-7)            {                for(int j=0;j<len-1-i;j++)                putchar(' ');                printf("%c\n",str[len-1-i]);            }            else if(n%8==2||n%8==-6)            {                for(int j=0;j<len/2;j++)                putchar(' ');                printf("%c\n",str[len-1-i]);            }            else if(n%8==3||n%8==-5)            {                for(int j=0;j<i;j++)                putchar(' ');                printf("%c\n",str[len-1-i]);            }            else if(n%8==4||n%8==-4)            {                putchar(str[len-1-i]);                if(i==len-1) putchar('\n');            }            else if(n%8==5||n%8==-3)            {                for(int j=0;j<len-1-i;j++)                putchar(' ');                printf("%c\n",str[i]);            }            else if(n%8==6||n%8==-2)            {                for(int j=0;j<len/2;j++)                putchar(' ');                printf("%c\n",str[i]);            }            else if(n%8==7||n%8==-1)            {                for(int j=0;j<i;j++)                putchar(' ');                printf("%c\n",str[i]);            }        }    }    return 0;}



 

原创粉丝点击