2011-12-20 19:19:01
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1256
题意:中文。
mark:wa了一次,算横排长度的时候用h/6忘了+1。
代码:
# include <stdio.h>
# include <string.h>
char g[110][110] ;
void output (char ch, int h)
{
int a = (h-3) /2 , b = (h-2) /2 ;
int c = 1 + h / 6 ;
int i, j ;
memset (g, ' ', sizeof (g)) ;
for (i = c ; i < c+b ; i++)
g[0][i] = g[a+1][i] = g[h-1][i] = ch ;
g[0][b+c] = g[a+1][b+c] = g[h-1][b+c] = '\0' ;
for (i = 1 ; i <= a ; i ++)
{
g[i][2*c+b] = '\0' ;
for (j = 0 ; j < c ; j++)
g[i][j] = g[i][j+c+b] = ch ;
}
for (i = a+2 ; i < h-1 ; i++)
{
g[i][2*c+b] = '\0' ;
for (j = 0 ; j < c ; j++)
g[i][j] = g[i][j+c+b] = ch ;
}
for (i = 0 ; i < h ; i++)
puts (g[i]) ;
}
int main ()
{
int T, h, flag = 0;
char ch ;
scanf ("%d%*c", &T) ;
while (T--)
{
scanf ("%c %d%*c", &ch, &h) ;
if (flag == 0) flag = 1 ;
else printf ("\n") ;
output (ch, h) ;
}
return 0 ;
}