1 条题解
-
0
C :
#include<stdio.h> int main(){ int n,i,j; scanf("%d",&n); int a[n][n]; for(i=0;i<n;i++){ a[i][0]=i+1; for(j=1;j<n-i;j++){ a[i][j]=a[i][j-1]+1; } for(j=n-i;j<n;j++){ if(j==n-i){ a[i][j]=1; }else{ a[i][j]=a[i][j-1]+1; } } } for(i=0;i<n;i++){ for(j=0;j<n;j++){ printf("%3c",(a[i][j]+'A'-1)); } printf("\n"); } return 0; }
C++ :
#include <iostream> #include <iomanip> using namespace std; int main(){ int a[10][10]; int i,j,n; cin>>n; for (i = 0;i < n;i++){ for (j = 0;j < n;j++){ if (i + j + 1 <= n){ a[i][j] = i + j + 1 + 64; }else{ a[i][j] = i + j + 1 - n + 64; } } } for (i = 0;i < n;i++){ for (j = 0;j < n;j++){ cout<<setw(3)<<char(a[i][j]); } cout<<endl; } }
Python :
def getList(m,n): ''' m 行数 n 列数 返回的是m行n列的二维数组,默认值为0 ''' ma = [ [0 for i in range(n)] for i in range(m) ] return ma def printList(arr): for i in arr: for j in i: print('%3s' %(chr(j + 64)) ,end='') print(); n = int( input() ); arr = getList(n,n) for i in range(0,n): k = i for j in range(0,n): arr[i][j] = k + 1 k += 1 if i + j == n - 1: k = 0 printList(arr) ''' 1 2 3 4 5 2 3 4 5 1 3 4 5 1 2 '''
- 1
信息
- ID
- 2114
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者