1538 迎春舞会之数字舞蹈 题解
题目地址:https://www.luogu.com.cn/problem/P1538
#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;
}

浙公网安备 33010602011771号