竞赛
考级
西外豚鼠精神状态良好
在保持代码一定可读性的同时,还极限压行进了十行,什么实力,不用说了
葬仪_亡蝶舞
点个赞吧QAQ
曼波
pipilong
卢某人
原神and崩铁
zsq-hugo
xerography
⨝
懒得喷
#include <bits/stdc++.h> using namespace std; int main() { int N; cin>>N; vector<vector<int>>magicSquare(N,vector<int>(N,0)); int row=0; int col=N/2; for(int num=1;num<=N*N;num++){ magicSquare[row][col]=num; int nextRow=(row-1+N)%N; int nextCol=(col+1)%N; if(magicSquare[nextRow][nextCol]!=0)row=(row+1)%N; else{ row=nextRow; col=nextCol; } } for (int i=0;i<N;i++) { for(int j=0;j<N;j++)cout<<magicSquare[i][j]<<" "; cout<<endl; } return 0; }
山河无恙
YuQing1919
用I,J定位,再做判断就行。 #include<iostream> using namespace std; int n,a[45][45],I,J; int main(){ cin>>n; I=0; J=n/2; for(int i=1;i<=n*n;i++){ a[I][J]=i; if(I-1<0&&J+1<n){ I=n-1; J++; } else if(I-1>=0&&J+1>=n){ I--; J=0; } else if(I-1<0&&J+1==n||a[I-1][J+1]){ I++; } else{ I--; J++; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ cout<<a[i][j]<<' '; } cout<<endl; } return 0; }
方俊程
#include<bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[40][40] = {0}; int row = 0, col = n / 2; a[row][col] = 1; for (int num = 2; num <= n * n; ++num) { int newRow = (row - 1 + n) % n; int newCol = (col + 1) % n; if (a[newRow][newCol] == 0) { } for (int i = 0; i<n;i++){ for (int j = 0; j < n; ++j) { cout << a[i][j] << " "; } cout << endl; } return 0; }
༺དༀ༒∞░∞༒ༀཌ༻
WA君
c++のsomebody