三种蛇形填数solve1
This commit is contained in:
42
others/test1.cpp
Normal file
42
others/test1.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
// 三种蛇形填数
|
||||
#include<bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 50;
|
||||
void solve1(){
|
||||
int a[N][N];
|
||||
int n; cin >> n;
|
||||
int sum = 1;
|
||||
for(int i = 1; i <= n; i++){
|
||||
if(i % 2){ // 列数是否为奇数, 是则向下顺序赋值
|
||||
for(int j = 1; j <= n; j++){
|
||||
a[j][i] = sum++;
|
||||
}
|
||||
}else{ // 列数为偶数, 顺序向上赋值
|
||||
for(int j = n; j >= 1; j--){
|
||||
a[j][i] = sum++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int i = 1; i <= n; i++){
|
||||
for(int j = 1; j <= n; j++){
|
||||
cout << setw(4) << a[i][j];
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
|
||||
void solve2(){
|
||||
int a[N][N];
|
||||
int n; cin >> n;
|
||||
int num = 1;
|
||||
for(int i = 0; n - 1 - 2*i >= 0; i++){
|
||||
for(int j = n - i; j <= n - 1 - 2*i; j++){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
solve1();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user