题解 | #蛇形矩阵#

蛇形矩阵

https://www.nowcoder.com/practice/649b210ef44446e3b1cd1be6fa4cab5e

#include <iostream>
using namespace std;
#include <unordered_map>
#include <string>
#include <set>
#include <vector>
#include<algorithm>
int main() {
	int arr[100][100];
	int n;
	cin >> n;
	int num = 0;
	num = 1 * n + n * (n - 1) / 2;
	int shu = 1;
	//最外侧下标和为n-1;
	for (int time = 1; time <= n; time++) {
		for (int i = 0; i < time; i++) {
			arr[time - 1 - i][i] = shu;
			shu += 1;
		}
	}
	for (int j = 0; j < n; j++) {
		for (int i = 0; i < n - j; i++) {
			cout << arr[j][i] << ' ';
		}
		cout << endl;
	}
	return 0;

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务