zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    至理明言100个经典句子
    ASP操作cookies的方法
    Recordset属性与方法
    VB.NET下用FSO(文件系统对象模型)实现获取硬盘信息
    诺基亚10个不为人知的秘密
    JavaScript的常用事件/方法/特效
    javascript常用方法
    C#操作xml
    URL重写
    数据库之间的区别
  • 原文地址:https://www.cnblogs.com/Duskcl/p/3973961.html
Copyright © 2011-2022 走看看