拐角I(C++)

Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 503 Solved: 406
[Submit][Status][Web Board]

Description

输入整数N,输出相应方阵。

Input

一个整数N。( 0 < n < 10 )

Output

一个方阵,每个数字的场宽为3。

Sample Input

5

Sample Output

  1  1  1  1  1
  1  2  2  2  2
  1  2  3  3  3
  1  2  3  4  4
  1  2  3  4  5

HINT

[Submit][Status]






仔细想一想每一行应怎么表示。

每行:1~行数,(行数+1)个行数。

代码:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int a;
    cin>>a;
    for(int i=1;i<=a;i++)
    {
        for(int j=1;j<=i;j++)
        {
            printf("%3d",j);
        }
        for(int u=1;u<=a-i;u++)
        {
            printf("%3d",i);
        }
        cout<<endl;
    }
 
    return 0;
}
原创文章 75 获赞 126 访问量 1万+

猜你喜欢

转载自blog.csdn.net/liuzich/article/details/105338404
今日推荐