hdu1256

http://acm.hdu.edu.cn/showproblem.php?pid=1256

ContractedBlock.gif ExpandedBlockStart.gif View Code
 
    
#include " iostream "
using namespace std;
int n,m;
int i,j;
char a[ 10 ];
int y;
int d; // d表示行的宽度
void fun1()
{
for ( i = 0 ;i < d - y;i ++ )
{
if (i < m / 6 + 1 ) printf( " " );
else printf( " %s " ,a);
}
printf(
" \n " );
}
void fun2( int x)
{
for (i = 0 ;i < x;i ++ )
{
for (j = 0 ;j < d;j ++ )
{
if (j < y || j > d - y - 1 ) printf( " %s " ,a);
else printf( " " );
}
printf(
" \n " );
}
}
int main()
{

cin
>> n;
while (n -- )
{
cin
>> a >> m;

// 分为五部分
y = m / 6 + 1 ;
d
= 2 * y + (m - 3 ) - (m - 3 ) / 2 ; // d表示行的宽度

fun1();
// (1)处理首行
fun2((m - 3 ) / 2 ); // (2)处理第一个矩形
fun1(); // (3)处理中间行
fun2((m - 3 ) - (m - 3 ) / 2 ); // (4)处理第二个矩形
fun1(); // (5)处理最后一行

if (n > 0 ) printf( " \n " );
}
return 0 ;
}

转载于:https://www.cnblogs.com/FCWORLD/archive/2011/04/07/2008117.html

猜你喜欢

转载自blog.csdn.net/weixin_34410662/article/details/94156073