2 条题解

  • -1
    @ 2024-5-25 14:56:16
    #include<iostream>
    using namespace std;
    int A[110][110];
    int main(){
    	int n,m;
    	cin >> n >> m;
    	for (int i = 0; i < n; i ++){
    		for (int j = 0; j < m; j ++){
    			cin >> A[i][j]; 
    		}
    	}
    	int a, b, c, d;
    	a = 0, b = 0, c = n - 1, d = m - 1;
    	while(a <= c && b <= d){
    		for (int i = b; i <= d; i ++){
    			cout << A[a][i] << " ";
    		}
    		for (int i = a + 1; i <= c; i ++){
    			cout << A[i][d] << " ";
    		}
    		if(a == c || b == d) break;
    		for (int i = d-1; i >= b; i --){
    			cout << A[c][i] << " ";
    		}
    		for (int i = c - 1; i >= a + 1; i --){
    			cout << A[i][b] << " ";
    		}
    		a++, b++, c--, d--;
    	}
    	return 0;
    } 
    

    信息

    ID
    129
    时间
    1000ms
    内存
    256MiB
    难度
    6
    标签
    (无)
    递交数
    103
    已通过
    29
    上传者