Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
2244 孙浚轩 方阵填数 C++ Compile Error 0 MS 0 KB 979 2023-12-23 00:27:02

Tests(0/0):


Code:

#include <iostream> #include <vector> usng namespace std; void generateMatrix(int N) { std::vector<std::vector<int>>matrix(N, std::vector<int>(N, 0)); int num=1; int row=0,col=0; int layer; if (N%2==0) layer=N/2; else layer=(N+1)/2; for(int i=0;i<layer;++i) { for(col = i; col < N - i; ++col) matrix[i][col] = num++; for(row = i + 1; row < N - i; ++row) matrix[row][N - i - 1] = num++; for(col = N - i - 2; col >= i; --col) matrix[N - i - 1][col] = num++; for(row = N - i - 2; row > i; --row) matrix[row][i] = num++; } for(int i=0;i<N;++i) { for(int j=0;j<N;++j) { cout << matrix[i][j]; if(j<N 1) cout << " "; } if(i<N-1) cout<<endl; } int main() { int n; cin>>n; generateMatrix(n); return 0; }


Run Info:

Main.cc:3:1: error: 'usng' does not name a type
 usng namespace std;
 ^
Main.cc: In function 'void generateMatrix(int)':
Main.cc:30:13: error: 'cout' was not declared in this scope
             cout < matrix[i][j];
             ^
Main.cc:30:13: note: suggested alternative:
In file included from Main.cc:1:0:
/usr/include/c++/4.8.2/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^
Main.cc:31:20: error: expected ')' before numeric constant
             if(j& __os)
     ^
Main.cc:39:1: error: a function-definition is not allowed here before '{' token
 {
 ^
Main.cc:44:1: error: expected '}' at end of input
 }
 ^