码迷,mamicode.com
首页 > 其他好文 > 详细

HDU2137 circumgyrate the string

时间:2014-09-23 12:38:44      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:hdu2137

circumgyrate the string

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


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
 

Source
 


#include <stdio.h>
#include <string.h>
#define maxn 100

char str[maxn];

void putBackspace(int n) {
    while(n--) putchar(' ');
}

void rotate(int cent, int n) {
    switch(n) {
        case 0:
        puts(str); return;
        case 1:
        for(int i = cent << 1, j = cent << 1; i >= 0; --j) {
            putBackspace(i--);
            printf("%c\n", str[j]);
        } return;
        case 2:
        for(int j = cent << 1; j >= 0; --j) {
            putBackspace(cent);
            printf("%c\n", str[j]);
        } return;
        case 3:
        for(int j = cent << 1, i = 0; j >= 0; --j) {
            putBackspace(i++);
            printf("%c\n", str[j]);
        } return;
        case 4:
        for(int j = cent << 1; j >= 0; --j) {
            printf("%c", str[j]);            
        } putchar('\n'); return;
        case 5:
        for(int j = 0, i = cent << 1; i >= 0; ++j) {
            putBackspace(i--);
            printf("%c\n", str[j]);
        } return;
        case 6:
        for(int j = 0; j <= cent << 1; ++j) {
            putBackspace(cent);
            printf("%c\n", str[j]);
        } return;
        case 7:
        for(int j = 0, i = 0; j <= cent << 1; ++j) {
            putBackspace(i++);
            printf("%c\n", str[j]);
        } return;
    }
}

int main() {
    int n, i, cent;
    while(scanf("%s%d", str, &n) != EOF) {
        cent = strlen(str) >> 1;
        n = (n % 8 + 8) % 8;
        rotate(cent, n);
    }
    return 0;
}


HDU2137 circumgyrate the string

标签:hdu2137

原文地址:http://blog.csdn.net/chang_mu/article/details/39496059

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!