1 条题解
-
0
C++ :
#include <iostream> #include <iomanip> #include <cmath> #include <cstdio> using namespace std; int main(){ int n,i,j,a[110][110]; cin>>n; for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ a[i][j]=((i-1)*n)+j; } } for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ cout<<setw(3)<<a[i][j]; } cout<<endl; } }
Python :
n = int(input()); def getArray(m,n): ''' :param m: 行 :param n: 列 :return: m行n列的二维数组 ''' array = [[0for i in range(n)] for i in range(m)]; return array; x = getArray(n,n); k = 1 for i in range(0,len(x)): for j in range(0,len(x[i])): x[i][j] = k; k += 1 #打印二维数组的代码 for i in x: for j in i: print('%3d'%(j),end='') print()
- 1
信息
- ID
- 2104
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- 10
- 标签
- 递交数
- 3
- 已通过
- 1
- 上传者