提交记录 #113
提交时间:2024-11-04 22:16:49
语言:c
状态:Unaccepted
编译情况:编译成功
code.c: In function ‘return_matrix’:
code.c:4:22: warning: ‘b’ may be used uninitialized in this function [-Wmaybe-uninitialized]
4 | L = 0, r, t, b;//四个赋值用的变量
| ^
code.c:4:19: warning: ‘t’ may be used uninitialized in this function [-Wmaybe-uninitialized]
4 | L = 0, r, t, b;//四个赋值用的变量
| ^
code.c:4:16: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized]
4 | L = 0, r, t, b;//四个赋值用的变量
| ^
固定测试点#1:
固定测试点#2:
固定测试点#3:
固定测试点#4:
固定测试点#5:
固定测试点#6:
固定测试点#7:
附加测试点暂不可用
H13【选做•图形】晕
#include<stdio.h>
void return_matrix(int a[][30], int n) {
int top = 0, bottom, left = 0, right,//矩形大小
L = 0, r, t, b;//四个赋值用的变量
int count = 1;//用于从1开始赋值
bottom = n - 1; right = n - 1;
if(n==2){
a[0][0]=1;
a[0][1]=2;
a[1][0]=4;
a[1][1]=3;
}
else if(n==1) a[0][0]=1;
else {
while (!(top == bottom && left == right)) {//回型赋值
while (L <= right) {
a[top][L] = count;
count++;
L++;
}
if (count <= n * n) { top++; t = top; }
while (t <= bottom) {
a[t][right] = count;
count++;
t++;
}
if (count <= n * n) { right--; r = right; }
while (r >= left) {
a[bottom][r] = count;
count++;
r--;
}
if (count <= n * n) { bottom--; b = bottom; }
while (b >= top) {
a[b][left] = count;
count++;
b--;
}
if (count <= n * n) { left++; L = left; }
}
if (n % 2 != 0) { a[top][left] = count; }
}//对n为单数的情况进行最后一项的赋值
}
int main() {
int a[30][30];//暂定为一个小型矩阵,所以二维数组小一点
int n = 0;//用户输入矩阵边长
scanf("%d", &n);
return_matrix(a, n);
for (int i = 0; i < n; i++) {//遍历输出
int j;
printf(" ");
for (j = 0; j < n-1; j++) {
if(a[i][j] < 100){
printf("%2d ", a[i][j]);
}else{
printf("%1d ", a[i][j]);
}
}
if(a[i][j] < 100){
printf("%2d\n", a[i][j]);
}else{
printf("%1d\n", a[i][j]);
}
}
return 0;
}