#include <iostream>
#include <cstdio>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n*n; i++) {
if (i < 10) cout << "0" << i;
else cout << i;
if (i % n == 0) cout << endl;
}
int cnt = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n-i; j++) {
cout << " ";
}
while (cnt <= i*(i+1)/2) {
if (cnt < 10) cout << "0" << cnt;
else {
cout << cnt;
}
cnt++;
}
cout << endl;
}
return 0;
}
打的正方形没问题,就是三角形居中了,而不是靠右对齐。
求助大佬们!