题解 | #蛇形矩阵#
蛇形矩阵
http://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e
#include <stdio.h>
#include <string.h>
static unsigned g_int[100][100] = {0};
int main(int argc, char** argv)
{
short matrix, val = 1;
scanf("%d", &matrix);
for (int i = 0; i < matrix; i++) for (int j = i; j >= 0; j--) g_int[j][i - j] = val++;
for (int i = 0; i < 100; i++) {
if (g_int[i][0] == 0) break;
for (int j = 0; j < 100; j++) { if (g_int[i][j] == 0) break; printf("%d ", g_int[i][j]); }
putchar('\n');
}
return 0;
}