[恢]hdu 1200

2011-12-16 13:07:53

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1200

题意:把一串字符竖着写成n列,得到一张表。现在横着把表的每行拼成一个字符串,其中奇数行(从0开始)反着拼。给你这个字符串求原来的加密前的字符串。

代码:

# include <stdio.h>


char str[210] ;
char dp[110][20] ;


int main ()
{
int i, j, cnt ;
int n, d, x, y ;
while (~scanf ("%d%*c", &n) && n)
{
gets (str) ;
cnt = 0 ;
x=y=0;
for (i = 0 ; str[i] ; i++)
{
dp[x][y] = str[i] ;
if (x%2==0){
y++ ;
if (y==n)x++,y-- ;
}
else{
y-- ;
if (y==-1)x++,y++ ;
}
}
for (i = 0 ; i < n ; i++)
for (j = 0 ; j < x ; j++)
putchar (dp[j][i]) ;
printf ("\n") ;
}

return 0 ;
}



原文地址:https://www.cnblogs.com/lzsz1212/p/2315014.html