ダディクールがC/C++の宿題を片づけます 32代目
レス数が900を超えています。1000を超えると表示できなくなるよ。
0910863
NGNG#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char* pos(char* data, int x, int y, int width){ return data + (width + 1) * y + x;}
int main(void){
int size, x = 0, y = 0, i;
char *matrix;
scanf("%d", &size);
matrix = (char*)malloc(sizeof(char) * (size + 1) * size);
memset(matrix, ' ', sizeof(char) * (size + 1) * size);
for (i = 0; i < size; ++i) *pos(matrix, size, i, size) = 0;
*pos(matrix, x, y, size) = '*';
for(; ; ) {
while (++x < size && *pos(matrix, x, y, size) == ' ') *pos(matrix, x, y, size) = '-';
*pos(matrix, --x, y, size) = '*';
if (*pos(matrix, x, y + 1, size) != ' ') goto exit_loop;
while (++y < size && *pos(matrix, x, y, size) == ' ') *pos(matrix, x, y, size) = '|';
*pos(matrix, x, --y, size) = '*';
if (*pos(matrix, x - 1, y, size) != ' ') goto exit_loop;
while (--x < size && *pos(matrix, x, y, size) == ' ') *pos(matrix, x, y, size) = '-';
*pos(matrix, ++x, y, size) = '*';
if (*pos(matrix, x, y - 1, size) != ' ') goto exit_loop;
while (--y < size && *pos(matrix, x, y, size) == ' ') *pos(matrix, x, y, size) = '|';
*pos(matrix, x, ++y, size) = '*';
if (*pos(matrix, x + 1, y, size) != ' ') goto exit_loop;
}
exit_loop:
for (i = 0; i < size; ++i) printf("%s\n", pos(matrix, 0, i, size));
free(matrix);
return 0;
}
レス数が900を超えています。1000を超えると表示できなくなるよ。