• cf 118B


    B. Present from Lena
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Vasya's birthday is approaching and Lena decided to sew a patterned handkerchief to him as a present. Lena chose digits from 0 to n as the pattern. The digits will form a rhombus. The largest digit n should be located in the centre. The digits should decrease as they approach the edges. For example, for n = 5 the handkerchief pattern should look like that:


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

    Your task is to determine the way the handkerchief will look like by the given n.

    Input

    The first line contains the single integer n (2 ≤ n ≤ 9).

    Output

    Print a picture for the given n. You should strictly observe the number of spaces before the first digit on each line. Every two adjacent digits in the same line should be separated by exactly one space. There should be no spaces after the last digit at the end of each line.

    Sample test(s)
    Input
    2
    Output
        0
    0 1 0
    0 1 2 1 0
    0 1 0
    0
    Input
    3
    Output
          0
    0 1 0
    0 1 2 1 0
    0 1 2 3 2 1 0
    0 1 2 1 0
    0 1 0
    0


     1 #include<map>
     2 #include<cmath>
     3 #include<queue>
     4 #include<cstdio>
     5 #include<vector>
     6 #include<string>
     7 #include<cstring>
     8 #include<sstream>
     9 #include<iostream>
    10 #include<algorithm>
    11 using namespace std;
    12 int main()
    13 {
    14     int n;
    15     cin>>n;
    16     for(int i = 0 ; i < n + 1; i ++)
    17     { 
    18         for(int j = 0 ; j < i * 2 + 1 ; j ++)
    19         {        
    20             for(int k = i*2 ; j==0 && k < n * 2 ; k++ )cout<<" ";
    21             if(j<=i&&j!=i*2)cout<<j<<" ";
    22             else if(j<=i)cout<<j;
    23             else if(j!=i*2)cout<<i*2-j<<" ";
    24                  else cout<<i*2-j;
    25         }
    26         cout<<endl;    
    27     }
    28     for(int i = 0 ; i < n  ; i++)
    29     { 
    30         for(int j = 0 ; j < (n - i )* 2 - 1 ; j++)
    31         {  
    32             for(int k = 0 ; j==0&& k < (i+1)*2 ; k++)cout<<" ";
    33             if(j<=n-i-1 && j!= (n-i)*2-2)cout<<j<<" ";
    34             else if(j<=n-i-1)cout<<j;
    35             else if(j!=(n-i)*2-2)cout<<(n-i -1)*2 -j <<" ";
    36                  else cout<<(n-i-1)*2-j;
    37         }
    38         cout<<endl;
    39     
    40     }
    41 }
  • 相关阅读:
    敌兵布阵(线段树单点更新+区间查询)
    小明上学(CCF认证2018-12-1 )
    There Are Two Types Of Burgers (Educational Codeforces Round 71)
    Bad Prices ( Codeforces Round #582 )
    Redis热点key优化
    Redis big key处理
    Redis的安全问题
    Redis的flushall/flushdb误操作
    Redis在linux系统中的优化
    Redis之缓存设计
  • 原文地址:https://www.cnblogs.com/Duskcl/p/3973961.html
Copyright © 2020-2023  润新知