Chúc mừng năm mới


Submit solution

Points: 3
Time limit: 1.0s
Memory limit: 977M

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, C, C++, C11, CLANG, CLANGX, Classical, COBOL, Coffee, CSC, D lang, DART, F95, FORTH, Fortrn, GAS32, GO, Haskell, Itercal, Java, kotlin, LEAN, LISP, LUA, MONOVB, Nasm, OCAML, Pascal, Perl, php, PIKE, prolog, Pypy, Python, Ruby 2, RUST, Scala, SCM, SED, SWIFT, TCL, TUR, V8JS, VB, ZIG

Bạn hãy trang trí ảnh chúc mừng năm mới là một hình chữ nhật có kích thước n(3n) ví dụ hình sau có kích thước 1339 với mẫu trang trí là dấu ".^."

Copy
------------------.^.------------------
---------------.^..^..^.---------------
------------.^..^..^..^..^.------------
---------.^..^..^..^..^..^..^.---------
------.^..^..^..^..^..^..^..^..^.------
---.^..^..^..^..^..^..^..^..^..^..^.---
-----------CHUC MUNG NAM MOI-----------
---.^..^..^..^..^..^..^..^..^..^..^.---
------.^..^..^..^..^..^..^..^..^.------
---------.^..^..^..^..^..^..^.---------
------------.^..^..^..^..^.------------
---------------.^..^..^.---------------
------------------.^.------------------

Input

Dòng đầu gồm số n là chiều cao của mẫu là một số lẻ có giá trị lớn hơn 10 nhỏ hơn 100

Dòng thứ 2 là mẫu trang trí gồm đúng 3 ký tự

Output

Với mỗi đầu vào bạn xuất ra ảnh trang trí chúc mừng năm mới

Ví dụ 1

Input

Copy
15
.*.

Output

Copy
---------------------.*.---------------------
------------------.*..*..*.------------------
---------------.*..*..*..*..*.---------------
------------.*..*..*..*..*..*..*.------------
---------.*..*..*..*..*..*..*..*..*.---------
------.*..*..*..*..*..*..*..*..*..*..*.------
---.*..*..*..*..*..*..*..*..*..*..*..*..*.---
--------------CHUC MUNG NAM MOI--------------
---.*..*..*..*..*..*..*..*..*..*..*..*..*.---
------.*..*..*..*..*..*..*..*..*..*..*.------
---------.*..*..*..*..*..*..*..*..*.---------
------------.*..*..*..*..*..*..*.------------
---------------.*..*..*..*..*.---------------
------------------.*..*..*.------------------
---------------------.*.---------------------

Ví dụ 2:

Input

Copy
11
<^>

Output

Copy
---------------<^>---------------
------------<^><^><^>------------
---------<^><^><^><^><^>---------
------<^><^><^><^><^><^><^>------
---<^><^><^><^><^><^><^><^><^>---
--------CHUC MUNG NAM MOI--------
---<^><^><^><^><^><^><^><^><^>---
------<^><^><^><^><^><^><^>------
---------<^><^><^><^><^>---------
------------<^><^><^>------------
---------------<^>---------------
tichpx

Comments


  • 1
    I_love_NguyenLinh  commented on Jan. 26, 2019, 4:28 p.m.

    code C#

    Copy
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();
            List<string> list = new List<string>();
            Enumerable.Range(0, n / 2).ToList().ForEach(x => list.Add(string.Join("", Enumerable.Repeat(s, x * 2 + 1)).center(n * 3, '-')));
            list.ForEach(x => Console.WriteLine(x));
            Console.WriteLine("CHUC MUNG NAM MOI".center(n * 3, '-'));
            list.AsEnumerable().Reverse().ToList().ForEach(x => Console.WriteLine(x));
            Console.ReadKey();
        }
    
        static string center(this string s, int m, char c) => s.PadLeft((m - s.Length) / 2 + s.Length, c).PadRight(m, c);

  • 1
    TICHPX  commented on Jan. 2, 2019, 4:49 a.m.

    Code tham khảo C/C++

    Copy
    #include<bits/stdc++.h>
    using namespace std;
    
    void out(string s, int w)
    {
        w=(w-s.length())/2;
        cout<<string(w,'-')+s+string(w,'-')<<endl;
    }
    int main()
    {
        int n;
        string p,s;
        cin>>n>>p;
        s=p;
        for(int i=1;i<(n+1)/2;i++) 
        {
            out(s,3*n);
            s+=p+p; 
        }
        out("CHUC MUNG NAM MOI",3*n);
        for(int i=1;i<(n+1)/2;i++) 
        {
            s.resize(s.length()-6);
            out(s,3*n);
        }   
    }

  • -2
    vtn  commented on Jan. 1, 2019, 4:31 p.m. edited

    Lần đầu code thất bại nó ra thế này :v :


    Copy
    8==D8==D8==D8==Dcmnm
    8==D8==D8==Dcmnmcmnmcmnm
    8==D8==Dcmnmcmnmcmnmcmnmcmnm
    8==Dcmnmcmnmcmnmcmnmcmnmcmnmcmnm
    cmnmcmnmcmnmcmnmcmnmcmnmcmnmcmnmcmnm
    8==Dcmnmcmnmcmnmcmnmcmnmcmnmcmnm
    8==D8==Dcmnmcmnmcmnmcmnmcmnm
    8==D8==D8==Dcmnmcmnmcmnm
    8==D8==D8==D8==Dcmnm

  • 2
    dangdungcntt  commented on Jan. 1, 2019, 3:56 p.m.

    Lần đầu giải bằng PHP

    Copy
    <?php
    $n = intval(fgets(STDIN));
    $p = trim(fgets(STDIN));
    $m = $n * 3;
    $n = floor($n / 2);
    $first = [];
    for ($i=1; $i <= $n; $i++) {
      $first[] = str_pad(str_repeat($p, 2 * $i - 1), $m, '-', STR_PAD_BOTH);
    }
    $last = array_reverse($first);
    $first[] = str_pad('CHUC MUNG NAM MOI', $m, '-', STR_PAD_BOTH);
    $output = array_merge($first, $last);
    fwrite(STDOUT, join(PHP_EOL, $output));

  • 1
    TICHPX  commented on Jan. 1, 2019, 2:44 p.m.

    Lần đầu ra đề bằng Python mời các bạn tham khảo code

    Copy
    n=int(input())
    p=input()
    m=n*3
    n//=2
    c=[""]
    for i in range (1,n+1): c.append(p*(2*i-1))
    for i in range (1,n+1): print(c[i].center(m,'-'))
    print("CHUC MUNG NAM MOI".center(m,'-'))
    for i in range (n,0,-1): print(c[i].center(m,'-'))