首页 > 其他分享 >1538 迎春舞会之数字舞蹈 题解

1538 迎春舞会之数字舞蹈 题解

时间:2023-01-20 11:44:54浏览次数:48  
标签:舞会 题解 segments number seven seg segment decimal 1538

#include <iostream>

int main()
{
    /*
     * # Seven-segment Display
     *
     * The way how the program prints decimal numerics to the console works
     * similarly to seven-segment displays. The seven segments are arranged as
     * a rectangle of two vertical segments on each side with one horizontal
     * segment on the top, middle and bottom. The following diagram depicts the
     * layout of seven segments,
     *
     *   -
     *  | |
     *   -
     *  | |
     *   -
     *
     * # The Working of Seven-segment Display
     *
     * The number 8 is displayed when all the segments are visible, and if you
     * hide the horizontal segment on the middle, then we get the number 0. We
     * can form different combinations of seven segments for decimal numerics
     * from 0 through 9. We number each segment starting 0 from top to bottom,
     * left to right, as illustrated in the following diagram,
     *
     * Layout    Serial Number
     *  -         0
     * | |       1 2
     *  -         3
     * | |       4 5
     *  -         6
     *
     * # Mapping
     *
     * By using a serial number as a subscript of string and its corresponding
     * segment as the contents(i.e. a char), serial numbers provide a way to map
     * any layout of decimal numeric to a string. Here is the mappings of all
     * decimal numerics.
     *
     *      "-||-||-" // types of segments
     *      "0123456" // numbers of segments
     * 0 -> "-|| ||-"
     * 1 -> "  |  | "
     * 2 -> "- |-| -"
     * 3 -> "- |- |-"
     * 4 -> " ||- | "
     * 5 -> "-| - |-"
     * 6 -> "-| -||-"
     * 7 -> "- |  | "
     * 8 -> "-||-||-"
     * 9 -> "-||- |-"
     *
     */

    char indiction [10][8] = {"-|| ||-"
                             ,"  |  | "
                             ,"- |-| -"
                             ,"- |- |-"
                             ," ||- | "
                             ,"-| - |-"
                             ,"-| -||-"
                             ,"- |  | "
                             ,"-||-||-"
                             ,"-||- |-"
                             };

    int  k;
    char digits[1000];

    std::cin >> k >> digits;

    for (int seg = 0; seg < 7; seg++)
    {
        if (seg == 2 || seg == 5) continue; // Skip those vertical segments, we will deal with those in 1, 4 together

        if (seg % 3 == 0)   // Horizontal segments
        {
            for (int d = 0; digits[d]; d++)
            {
                std::cout << ' ';
                for (int i = 0; i < k; i++)
                {
                    std::cout << indiction[digits[d]-48][seg];
                }
                std::cout << "  ";
            }
            std::cout << '\n'; // EOL
        }
        else    // Vertical segments
        {
            for (int i = 0; i < k; i++)
            {
                for (int d = 0; digits[d]; d++)
                {
                    std::cout << indiction[digits[d]-48][seg];
                    for (int j = 0; j < k; j++)
                    {
                        std::cout << ' ';
                    }
                    std::cout << indiction[digits[d]-48][seg+1] << ' ';
                }
                std::cout << '\n'; // EOL
            }
        }
    }
    return 0;
}

 

标签:舞会,题解,segments,number,seven,seg,segment,decimal,1538
From: https://www.cnblogs.com/revc/p/17062481.html

相关文章

  • CF225 Round #139 题解
    比赛链接:https://codeforces.com/contest/225题解:A题意题//bySkyRainWind#include<bits/stdc++.h>#definemprmake_pair#definedebug()cerr<<"Yoshino\n"#de......
  • 题解 ABC231D【Neighbors】
    首先,每个数不能有超过两个相邻元素,不然无法构成一条链。可以通过记录每个数出现次数(度数)来判断。其次,给的信息不能成环,不然也无法构成一条链。可以通过并查集来判断。在......
  • 题解 ARC115C【ℕ Coloring】
    显然\(A_1,A_2,A_4,A_8,\cdots\)必须互不相同,因此最大的数一定不小于\(\lfloor\log_2n\rfloor+1\),猜想可以取到\(\lfloor\log_2n\rfloor+1\)。构造\(A_i=\lfloor\log......
  • 2023牛客寒假算法基础集训营2题解
    写在前面菜菜,哭哭,大佬救救QaQ理解大佬的代码并且整理成一篇博客真的很累...C:Tokitsukazeanda+b=n(hard)1.本蒟蒻的代码个人感觉用前缀和更方便。我最开始用的是线......
  • CF622F The Sum of the k-th Powers 题解
    观前提示本题解仅提供一个理论复杂度正确的解法,因为本题模数为\(10^9+7\),没有优秀\(\text{MTT}\)板子的我被卡常了。正文部分不妨设\(S_{n,m}=\sum_{i=0}^{n-1}i^m......
  • CF576C 题解
    注意到\(\sum\limits_{i=2}^N|x_{p_i}-x_{p_{i-1}}|+|y_{p_i}-y_{p_{i-1}}|\)。本质上是两个点之间的曼哈顿距离。而曼哈顿最小距离生成树要\(O(n^2\logn)\)......
  • CF1768B 题解
    首先我们思考什么数是不用排序的。显然,序列中一个由\(1\)开始,每次递增\(1\)的子序列是不用排序的。为什么呢?因为我们把其他数按从大到小排好后这个子序列刚好构成排......
  • 洛谷P4983 忘情 题解报告
    题目地址题意:把正整数序列分隔为m个区间,若单个区间的元素之和为X,则其贡献为\((X+1)^2\)。求所有区间的贡献之和的最小值。分析:wqs二分+斜率优化dp。用单调队列发可......
  • abc273G题解
    \(dp[i][j]\):考虑到前i行,有j个2的方案数。设有k个1(计算可得)。\(a_{i+1}=0\):\(dp[i][j]\todp[i+1][j]\)\(a_{i+1}=1\):\(dp[i][j]\times(n-j-k)\todp[......
  • win10下python3.9的代理报错问题解决(附web3的polygon爬虫源码)
    背景因为工作中经常需要代理访问,而开了代理,request就会报错SSLError,如下:requests.exceptions.SSLError:HTTPSConnectionPool(host='test-admin.xxx.cn',port=443):Ma......