HDU 1256【画8】
画八。水?
看了网上别人的博客,但感觉她写的有点问题,结合自己的理解修改了一下代码,但思路是一样的。
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
int t, N, col, row,flag;
char c;
cin >> t;
while (t--)
{
flag = 0;
cin >> c >> N;
col = 1+N/6;
if ((N - 3) % 2 == 0) { //优先级如果用 !(N-3)%2,先计算的是!然后是%,要用!((N-3)%2)
row = (N - 3) / 2;
flag = 1;
}
else
row = (N-3)/2 + 1;
for (int i = 0; i < N; i++)
{
if (i == 0 || i == N - 1 || i ==(flag?row+1:row) ) //根据输出结果打的补丁
{
for (int j = 1; j <= col; j++)
cout << " ";
for (int j = col+1; j <= row+col; j++)
printf_s("%c", c);
cout << endl;
}
else {
for (int i = 1; i <= col; i++)
printf_s("%c", c);
for (int i = col+1; i <=col+row; i++)
cout << " ";
for (int i = col + row+1; i <= 2*col+row; i++)
printf_s("%c", c);
cout << endl;
}
}
if (t) cout << endl;
}
return 0;
}