【HDOJ】1200 To and Fro

简单字符串练习,不用想太多,直接printf。

#include <stdio.h>
#include <string.h>

#define MAXCHARNUM 205

char buf[MAXCHARNUM];
char org[MAXCHARNUM];

/*
 * t o i o y
   h p k n n // n n k p h
   e l e a i
   r a h s g // g s h a r
   e c o n h
   s e m o t // t o m e s
   n l e w x

 * toioynnkpheleaigshareconhtomesnlewx
 * theresn oplacel ikehome onasnow ynightx
 */

int main() {
    int col;
    int i, j, row, tmp;

    while (scanf("%d", &col)!=EOF && col) {
        getchar();
        gets(buf);
        row = strlen(buf) / col;
        for (i=0; i<col; ++i) {
            for (j=0, tmp=0; j<row; ++j, tmp+=col) {
                if (j&1)
                    printf("%c", buf[tmp+col-1-i]);
                else
                    printf("%c", buf[tmp+i]);
            }
        }
        printf("\n");
    }

    return 0;
}

 

posted on 2014-03-16 22:53  Bombe  阅读(166)  评论(0编辑  收藏  举报

导航