HDU 2037 circumgyrate the string(字符串翻转)

circumgyrate the string

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

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

AC代码:
#include<iostream>  
#include<memory.h>  
#include<cstdlib>  
#include<cstdio>  
#include<cmath>  
#include<cstring>  
#include<string>  
#include<cstdlib>  
#include<iomanip>  
#include<vector>  
#include<list>  
#include<map>  
#include<algorithm>  
typedef long long LL;  
using namespace std; 
const LL maxn=1e6;
const LL mod=10000000; 
//输入一个字符串,再输入旋转次数,每次转动45度,注意number可以是负数 
char str[80 + 5];
int main()
{
    int number;
    while(scanf("%s%d", str, &number) != EOF)
    {
        int len = strlen(str);
        if(number % 8 == 0)
        {
            for(int i = 0; i < len; i++)
                printf("%c", str[i]);
            printf("\n");
        }
        else if(number % 8 == 1 || number % 8 == -7)
        {
            for(int i = len - 1; i >= 0; i--)
            {
                for(int j = 0; j < i; j++)
                printf(" ");
                printf("%c\n", str[i]);

            }
        }
        else if(number % 8 == 2 || number % 8 == -6)
        {
            for(int i = 0; i < len; i++)
            {
                for(int j = 0; j < len / 2; j++)
                    printf(" ");
                printf("%c\n", str[len - 1 - i]);
            }
        }
        else if(number % 8 == 3 || number % 8 == -5)
        {
            for(int i = 0; i < len; i++)
            {
                for(int j = 0; j < i; j++)
                printf(" ");
                printf("%c\n", str[len - 1 - i]);

            }
        }
        else if(number % 8 == 4 || number % 8 == -4)
        {
            for(int i = len - 1; i >= 0; i--)
                printf("%c", str[i]);
            printf("\n");
        }
        else if(number % 8 == 5 || number % 8 == -3)
        {
            for(int i = 0; i < len; i++)
            {
                for(int j = 0; j < len - i - 1; j++)
                    printf(" ");
                printf("%c\n", str[i]);
            }
        }
        else if(number % 8 == 6 || number % 8 == -2)
        {
            for(int i = 0; i < len; i++)
            {
                for(int j = 0; j < len / 2; j++)
                    printf(" ");
                printf("%c\n", str[i]);
            }
        }
        else if(number % 8 == 7 || number % 8 == -1)
        {
            for(int i = 0; i < len; i++)
            {
                for(int j = 0; j < i; j++)
                printf(" ");
                printf("%c\n", str[i]);

            }
        }
    }
    return 0;
}


 

你可能感兴趣的:(str,HDU,the,字符串翻转,2037,circumgyrate)