zoukankan      html  css  js  c++  java
  • [ACM] hdu 4706 Children's Day

    Children's Day

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 10   Accepted Submission(s) : 5

    Font: Times New Roman | Verdana | Georgia

    Font Size:  

    Problem Description

    Today is Children's Day. Some children ask you to output a big letter 'N'. 'N' is constituted by two vertical linesand one diagonal. Each pixel of this letter is a character orderly. No tail blank is allowed.
    For example, this is a big 'N' start with 'a' and it's size is 3.
    a e
    bdf
    c g
    

    Your task is to write different 'N' from size 3 to size 10. The pixel character used is from 'a' to 'z' continuously and periodic('a' is reused after 'z').

    Input

    This problem has no input.

    Output

    Output different 'N' from size 3 to size 10. There is no blank line among output.

    Sample Output

    [pre]
    a e
    bdf
    c g
    h  n
    i mo
    jl p
    k  q
    .........
    r        j
    [/pre]
    

    Hint

    Not all the resultsare listed in the sample. There are just some lines. The ellipsis expresseswhat you should write.

    Source

    2013 ACM/ICPC Asia Regional Online —— Warmup


    解题思路:

    样例中怎么给,我们就跟着怎么做,模拟输出图形。该题属于比较简单的。字母从a开始一直到z,再从a开始,所以我们只要用一个全局变量 char s='a'。对于每个'N'图形,先最左边竖着在数组中填字母,然后从左上角向右上角填字母,最后从最右边竖着填字母。记得判断s的值,如果大于'z',要重新赋值为’a' .

    代码:

    #include <iostream>
    #include <string.h>
    using namespace std;
    char tu[11][11];
    char s='a';
    
    void output(int n)
    {
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
            tu[i][j]=' ';//初始化数组
        for(int i=1;i<=n;i++)//最左边竖着填字母
            {
                tu[i][1]=s++;
                if(s>'z')
                    s='a';
            }
        for(int i=n-1;i>=2;i--)//斜着从左向右填字母
            {
                tu[i][n-i+1]=s++;
                if(s>'z')
                    s='a';
            }
        for(int i=1;i<=n;i++)//最右边竖着填字母
            {
                tu[i][n]=s++;
                if(s>'z')
                    s='a';
            }
        for(int i=1;i<=n;i++)//输出“N'图形
        {
            for(int j=1;j<=n;j++)
                cout<<tu[i][j];
            cout<<endl;
        }
    }
    
    int main()
    {
        for(int i=3;i<=10;i++)
            output(i);
        return 0;
    }
    

    运行截图:


  • 相关阅读:
    SpringBoot前端模板
    Http协议与TCP协议简单理解
    Kafka简介、基本原理、执行流程与使用场景
    初学Kafka工作原理流程介绍
    Redis数据持久化、数据备份、数据的故障恢复
    zookeeper的分布式锁
    eclipse下将maven项目打包为jar(1.不带第三方jar,2.带第三方jar)
    Redis入门篇(安装与启动)
    java操作Redis缓存设置过期时间
    java单例模式实现
  • 原文地址:https://www.cnblogs.com/sr1993/p/3697964.html
Copyright © 2011-2022 走看看