circumgyrate the string 2137

来源:互联网 发布:上海交大网络空间安全 编辑:程序博客网 时间:2024/05/18 21:41

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

#include <iostream>#include <cstring>#include <string>#include <cstdio>int main(int argc, const char* argv[]){    std::string sz;    int n;    while (std::cin >> sz)    {        //if(!(std::cin >> n)) break; ///可能cin对类型检查比较严格、有数据没有被处理        if (scanf("%d", &n) == EOF) break;        if (n<0)        {            n = -n;            n = 8-n%8;        }        int l = strlen(sz.c_str());        if (n % 8 == 0)        {            std::cout << sz << std::endl;        }        else if (n % 8 == 1)        {            int m = l - 1;            for (int i=l-1; i>=0; --i)            {                for (int j=0; j<m; ++j)                {                    std::cout << " ";                }                std::cout << sz[i] << std::endl;                --m;            }        }        else if (n % 8 == 2)        {            int m = l/2;            for (int i=l-1; i>=0; --i)            {                for (int j=0; j<m; ++j)                {                    std::cout << " ";                }                std::cout << sz[i] << std::endl;            }        }        else if (n % 8 == 3)        {            int m = 0;            for (int i=l-1; i>=0; --i)            {                for (int j=0; j<m; ++j)                {                    std::cout << " ";                }                std::cout << sz[i] << std::endl;                ++m;            }        }        else if (n % 8 == 4)        {            for (int i=l-1; i>=0; --i)            {                std::cout << sz[i];            }            std::cout << std::endl;        }        else if (n % 8 == 5)        {            int m = l - 1;            for (int i=0; i<l; ++i)            {                for (int j=0; j<m; ++j)                {                    std::cout << " ";                }                std::cout << sz[i] << std::endl;                --m;            }        }        else if (n % 8 == 6)        {            int m = l/2;            for (int i=0; i<l; ++i)            {                for (int j=0; j<m; ++j)                {                    std::cout << " ";                }                std::cout << sz[i] << std::endl;            }        }        else        {            int m = 0;            for (int i=0; i<l; ++i)            {                for (int j=0; j<m; ++j)                {                    std::cout << " ";                }                std::cout << sz[i] << std::endl;                ++m;            }        }    }    return 0;}
0 0
原创粉丝点击