文章目录
题目![在这里插入图片描述](https://img-blog.csdnimg.cn/2340a76f57c7440d937ed2b38107f60f.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBA5LiA6KKN5riF6YWS5LuYODI1,size_20,color_FFFFFF,t_70,g_se,x_16)
AC代码
#include <bits/stdc++.h>
using namespace std;
int arr[105][105];
int main() {
int n;
cin >> n;
int a = (n + 1) * n / 2; //最后的和
int turn = 1;
int temp;//定义一个临时变量记录向上走之前的数
arr[0][0] = 1;
int x = 1, y = 0, sum = 2; //开始坐标以及开始的数
for (sum = 2; sum <= a; ++sum) {
arr[x][y] = sum;
if (y == 0)
temp = x + 1;
if (x != 0) {
x--;
y++;
} else {
x = temp;
y = 0;
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n - i; ++j) {
cout << arr[i][j] << " ";
}
cout << endl;
}
}
跟着些就好了~