注意:
①題中已經規定,數據規模不超過9。
②小於10的數,輸出要補0
AC代碼:
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
scanf("%d", &n);
for(int i=1; i<=n*n; i++){ //處理正方形
if(i<10){
printf("0%d", i);
}
else
{
printf("%d", i);
}
if(i%n==0){
printf("\n");
}
}
printf("\n");
int temp=1; //處理三角形
for(int j=1; j<=n; j++){
for(int i=1; i<=n-j; i++){
printf(" "); //兩個空格
}
for(int k=1; k<=j; k++){
if(temp<10){
printf("0%d", temp);
}
else
{
printf("%d",temp);
}
temp++;
}
printf("\n");
}
return 0;
}