poj_1099

#include "stdio.h"
int main()
{
char printVector[200][200] = {'0'}; //存储每行输出 0:空格 1:H 2:O 3:- 4:| 
int scanfVector[50][50];    //存储矩形输入
int scanfSide[10] = {0};           //存储输入的矩形边长
int n = 0;
int num = 0;
int rankNum = 0; //记录O当前的行数
while (scanf("%d", &n), n)
{
scanfSide[num++] = n;
int i;
for (i = 0; i < n; i++)
{
//rankNum ++; //记录当前列数
int rowNum = 2; //记录O在当前行的列数
int j;
for (j = 0; j < n; j++)
{
//rowNum ++;
scanf("%d", &scanfVector[i][j]);
if (scanfVector[i][j] == 1)
{
printVector[rankNum][rowNum - 2] = 'H';
printVector[rankNum][rowNum - 1] = '-';
printVector[rankNum][rowNum] =     'O';
printVector[rankNum][rowNum + 1] = '-';
printVector[rankNum][rowNum + 2] = 'H';
}
else if (scanfVector[i][j] == -1)
{
if(rankNum - 2 < 0)
continue;
printVector[rankNum - 2][rowNum] = 'H';
printVector[rankNum - 1][rowNum] = '|';
printVector[rankNum][rowNum] =     'O';
printVector[rankNum + 1][rowNum] = '|';
printVector[rankNum + 2][rowNum] = 'H';
}
else if (scanfVector[i][j] == 0)//类型和他前一个字符有关
{
//朝下
if (i == 0 || printVector[rankNum - 2][rowNum] == 'H')
{
//朝左
if (j == 0 || printVector[rankNum][rowNum - 2] != 'H')
{
printVector[rankNum][rowNum - 2] = 'H';
printVector[rankNum][rowNum - 1] = '-';
printVector[rankNum][rowNum] = 'O';
printVector[rankNum + 1][rowNum] = '|';
printVector[rankNum + 2][rowNum] = 'H';
}
else
{
printVector[rankNum][rowNum + 2] = 'H';
printVector[rankNum][rowNum + 1] = '-';
printVector[rankNum][rowNum] = 'O';
printVector[rankNum + 1][rowNum] = '|';
printVector[rankNum + 2][rowNum] = 'H';
}
}
else //朝上
{
if (rankNum - 2 < 0)
continue;
//朝左
if (j == 0 || printVector[rankNum][rowNum - 2] != 'H')
{
printVector[rankNum - 2][rowNum] = 'H';
printVector[rankNum - 1][rowNum] = '|';
printVector[rankNum][rowNum] = 'O';
printVector[rankNum][rowNum - 1] = '-';
printVector[rankNum][rowNum - 2] = 'H';
}
else
{
printVector[rankNum - 2][rowNum] = 'H';
printVector[rankNum - 1][rowNum] = '|';
printVector[rankNum][rowNum] = 'O';
printVector[rankNum][rowNum + 1] = '-';
printVector[rankNum][rowNum + 2] = 'H';
}
}
}
rowNum += 4; //
}
if (i < n - 1)
rankNum += 4;
else
rankNum++;
}
}


int tempRank = 0;
int rank = 0;
int i;
for (i = 0;i < num;i++)
{
printf("Case %d\n\n",i + 1);
for (rank = tempRank; rank <= (scanfSide[i] - 1) * 4 + tempRank; rank++)
{
第一行****
if(rank == tempRank)
{
int k;
for (k = 0; k <= scanfSide[i] * 4 + 2; k++)
{
printf("*");
}
printf("\n");
}

每行第一个*
printf("*");
int row;
for (row = 0; row <= scanfSide[i] * 4; row++)
{
if (printVector[rank][row] != '0')
printf("%c", printVector[rank][row]);
else
printf(" ");
}
每行最后一个*
printf("*");
printf("\n");
/
/最后一行****
if (rank == (scanfSide[i] - 1) * 4 + tempRank)
{
int k;
for (k = 0; k <= scanfSide[i] * 4 + 2; k++)
{
printf("*");
}
printf("\n\n");
}
}
tempRank = rank;
}
return 0;
}

你可能感兴趣的:(算法学习)