HDU 2137 circumgyrate the string

把题意搞懂,就是一个字符串的旋转,然后模拟一遍就好~

 

                                                                                                          circumgyrate the string

                                              Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

 

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 <stdio.h>
#include <stdlib.h>
#include <string.h>

char name[100];
int n;

int main()
{
    while( scanf("%s",name) == 1 ){
           int t = strlen(name);
           scanf("%d",&n);
           n %= 8;
           if( n < 0 )
               n += 8;
           if( n == 0 )
               printf("%s\n",name);
           else if( n==4 ){
                for( int i=t-1 ; i>=0 ; i-- )
                     printf("%c",name[i]);
                printf("\n");     
           }
           else if( n == 1 ){
                for( int i=t-1; i>=0 ; i-- ){
                     for( int j=i ; j>0 ; j-- )
                          printf(" ");
                     printf("%c\n",name[i]);
                }
           }
           else if( n == 2 ){
                for( int i=t-1 ; i>=0 ; i-- ){
                     for( int j=0 ; j<(t/2) ; j++ )
                          printf(" ");
                printf("%c\n",name[i]);     
                }
           }
           else if( n == 3 ){
                for( int i=t-1 ; i>=0 ; i-- ){
                     for( int j=t-1 ; j>i ; j-- )
                          printf(" ");
                     printf("%c",name[i]);
                     printf("\n");
                }
           }
           else if( n == 5 ){
                for( int i=0 ; i<t ; i++ ){
                     for( int j=i+1 ; j<t ; j++ )
                          printf(" ");
                     printf("%c\n",name[i]);
                }
           }
           else if( n == 6 ){
                for( int i=0 ; i<t ; i++ ){
                     for( int j=0 ; j<t/2 ; j++ )
                          printf(" ");
                printf("%c\n",name[i]);    
                } 
           }
           else if( n == 7 ){
                for( int i=0 ; i<t ; i++ ){
                     for( int j=0 ; j<i ; j++ )
                          printf(" ");
                     printf("%c\n",name[i]);                           
                }     
           }
    }    
    return 0;
}


 

你可能感兴趣的:(HDU 2137 circumgyrate the string)