ac代码
2025-01-25 18:03:30
发布于:北京
3阅读
0回复
0点赞
思路
可以先把普通的序列存进数组里:
1 5 9 13
2 6 10 14
3 7 11 15
4 8 12 16
再把偶数列倒过来输出。
代码
#include <iostream>
using namespace std;
int a[100][100];//定义
int main() {
int n;
int cnt=0;//一定要初始化为0
cin>>n;
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
a[j][i]=++cnt;//不是cnt+1
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(j%2==0){
cout<<a[n-i+1][j]<<" ";//难点
}
else{
cout<<a[i][j]<<" ";
}
}
cout<<endl;
}
return 0;
}
这里空空如也
有帮助,赞一个