提交记录 #138
提交时间:2024-11-05 21:37:52
语言:c
状态:Unaccepted
编译情况:编译成功
固定测试点#1:
固定测试点#2:
固定测试点#3:
固定测试点#4:
固定测试点#5:
固定测试点#6:
固定测试点#7:
附加测试点暂不可用
H13【选做•图形】晕
#include <stdio.h>
void printSpiral(int n) {
int value = 1;
int top = 0, bottom = n - 1, left = 0, right = n - 1;
while (top <= bottom && left <= right) {
for (int i = left; i <= right; i++) {
printf("%3d", value++);
}
top++;
for (int i = top; i <= bottom; i++) {
printf("%3d", value++);
}
right--;
if (top <= bottom) {
for (int i = right; i >= left; i--) {
printf("%3d", value++);
}
bottom--;
}
if (left <= right) {
for (int i = bottom; i >= top; i--) {
printf("%3d", value++);
}
left++;
}
}
}
int main() {
int n;
scanf("%d", &n);
printSpiral(n);
return 0;
}