HDU 2137 circumgyrate the string

HDU 2137 circumgyrate the string


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

简单的字符串处理问题,但是有几个注意点:

1、输入有可能是负数
2、当输入是2或6时,注意前面的空格,要不然会PE的

一共八种情况,一一个一个的写就行了,比较麻烦

代码如下:


#include<iostream>
#include <cstdio>
#include <string.h>
using namespace std;

int main()
{
#ifndef  ONLINE_JUDGE
    freopen("1.txt","r",stdin);  
#endif
    char a[85];
    int n, len, i, j;
    while(~scanf("%s%d", a, &n)) 
    {
        while (n < 0)
        {
            n += 8;
        }
        if (n >= 8)
        {
            n %= 8;
        }

        len = strlen(a);
        if (n == 0)
        {
            cout << a << endl;
        }
        else if (n == 1)
        {
            for (i = len - 1; i >= 0; i--)
            {
                for(j = 1; j <= i; j++)
                {
                    printf(" ");
                }
                cout << a[i] << endl;
            }

        }
        else if (n == 2)
        {
            for (i = len - 1; i >= 0; i--)
            {
                for (j = 0; j < len/2; j++)
                    cout << " ";
                printf("%c\n", a[i]);
            }
        }
        else if (n == 3)
        {
            for (i = len - 1; i >= 0; i--)
            {
                for (j = 1; j < len - i; j++)
                {
                    printf(" ");
                }
                cout << a[i];

                cout << endl;
            }
        }
        else if (n == 4)
        {
            for (i = len - 1; i >= 0; i--)
            {
                cout << a[i];
            }
            cout << endl;
        }
        else if (n == 5)
        {
            for (i = 0; i < len; i++)
            {
                for(j = 1; j < len - i; j++ )
                {
                    printf(" ");
                }
                cout << a[i] << endl;
            }
        }
        else if (n == 6)
        {
            for (i = 0; i < len ; i++)
            {
                for(j = 1; j <= len/2; j++)
                {
                    printf(" ");
                }
                printf("%c\n", a[i]);
            }
        }
        else if (n == 7)
        {
            for(i = 0; i < len; i++)
            {
                for(j = 0; j < i; j++)
                {
                    cout << " ";
                }
                cout << a[i] << endl;
            }
        }
    //  cout << endl << endl;
    }
    return 0;
} 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值