hd2137

circumgyrate the string

Time Limit: 10000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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
 
题目大意就是一字符串,嗯,长度总为奇数,以中间的字符为轴逆时针旋转,每次旋转45度。
 
不造有木有可以不用从0到7一个一个写的方法,挺麻烦,
嗯,注意n可以为负
 
<pre name="code" class="html">#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,j,lens;
    char s[100];
    while(~scanf("%s %d",s,&n))
    {
        
        n=n%8;
        if(n<0)n+=8;
        lens=strlen(s);
        if(n==0)printf("%s\n",s);
        else if(n==1)
        {
            for(i=0;i<lens;++i)
            {
                for(j=0;j<lens;++j)
                {
                    if(j<lens-i-1)printf(" ");
                    else if(j==lens-i-1)printf("%c",s[lens-i-1]);
                }
                printf("\n");
            }
        }
        else if(n==2)
        {
            for(i=0;i<lens;++i)
            {
                for(j=0;j<lens;++j)
                {
                    if(j<(lens-1)/2)printf(" ");
                    else if(j==(lens-1)/2)printf("%c",s[lens-1-i]);
                }
                printf("\n");
            }
        }
        else if(n==3)
        {
            for(i=0;i<lens;++i)
            {
                for(j=0;j<lens;++j)
                {
                    if(j<i)printf(" ");
                    else if(j==i)printf("%c",s[lens-i-1]);
                }
                printf("\n");
            }
        }
        else if(n==4)
        {
            for(i=lens-1;i>=0;i--)printf("%c",s[i]);
            printf("\n");
        }
        else if(n==5)
        {
            for(i=0;i<lens;++i)
            {
                for(j=0;j<lens;++j)
                {
                    if(j<lens-i-1)printf(" ");
                    else if(j==lens-i-1)printf("%c",s[i]);
                }
                printf("\n");
            }
        }
        else if(n==6)
        {
            for(i=0;i<lens;++i)
            {
                for(j=0;j<lens;++j)
                {
                    if(j<(lens-1)/2)printf(" ");
                    else if(j==(lens-1)/2)printf("%c",s[i]);
                }
                printf("\n");
            }
        }
        else if(n==7)
        {
            for(i=0;i<lens;++i)
            {
                for(j=0;j<lens;++j)
                {
                    if(j<i)printf(" ");
                    else if(j==i)printf("%c",s[i]);
                }
                printf("\n");
            }
        }
    }
    return 0;
}


 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值