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 }
  • 相关阅读:
    多表查询+多对多 三表连查+子查询
    几个重要的关键字where+group by +having +order by + limit
    拷贝表 *** 与******
    一对一关系的补充
    几种基本的约束和外键(一对一 多对多 多对一)级联关系
    创建表的完整语法 数字类型(整型 浮点型) 字符型 时间和日期类型 集合和枚举类型
    随记Litter note
    视图 触发器 事务(重要) 存储过程 内置函数 流程控制 索引
    luogu P2774 方格取数问题
    luogu P4014 分配问题
  • 原文地址:https://www.cnblogs.com/Duskcl/p/3973961.html
Copyright © 2011-2022 走看看