输入包含多组数据,每组数据包含两个整数s(1≤s≤10)和n(1≤n≤99999999)。
其中n 是要显示的数,s 是要显示的数的尺寸。
显示的方式是:用 s 个“-”表示一个水平线段,用s 个“|”表示一个垂直线段。这种情况下,每一个数字需要占用s+2 列和2s+3 行。
另外,在两个数字之间要输出一个空白的列。每组数据之后输出一个空行作为分隔。
注意:输出中空白的地方都要用空格来填充。
2 12345 3 67890
-- -- -- | | | | | | | | | | | | -- -- -- -- | | | | | | | | | | -- -- -- --- --- --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- | | | | | | | | | | | | | | | | | | | | | | | | --- --- --- ---
#include <cstdio>
#include <iostream> #include <string> using namespace std; const unsigned char table[10] = { 0x77, 0x12, 0x5D, 0x5B, 0x3A, 0x6B, 0x6F, 0x52, 0xFF, 0x7B }; void printHorizon(string & str, int n, int off) { for (int i = 0; i < str.size(); ++i) { cout << (i ? " " : ""); cout << ' '; for (int j = 0; j < n; ++j) cout << ((table[str[i] - '0'] >> off) & 0x01 ? '-' : ' '); cout << ' '; } cout << endl; } void printVertical(string & str, int n, int off) { for (int j = 0; j < n; ++j) { for (int i = 0; i < str.size(); ++i) { cout << (i ? " " : ""); cout << ((table[str[i] - '0'] >> off) & 0x01 ? '|' : ' '); for (int k = 0; k < n; ++k) cout << ' '; cout << ((table[str[i] - '0'] >> (off - 1)) & 0x01 ? '|' : ' '); } cout << endl; } } void print(string & str, int n) { printHorizon(str, n, 6); printVertical(str, n, 5); printHorizon(str, n, 3); printVertical(str, n, 2); printHorizon(str, n, 0); cout << endl; } int main() { int n; string str; while (cin >> n >> str) { print(str, n); } return 0; }
#include <stdio.h> #include <string.h> #define DIGIT 8 #define MAX_LEN 11 const char seg[10][7] = {{1,1,1,0,1,1,1}, {0,0,1,0,0,1,0}, {1,0,1,1,1,0,1}, /*0-9的七段数码管是否亮起*/{1,0,1,1,0,1,1}, {0,1,1,1,0,1,0}, {1,1,0,1,0,1,1}, {1,1,0,1,1,1,1}, {1,0,1,0,0,1,0}, {1,1,1,1,1,1,1}, {1,1,1,1,0,1,1}}; int main() { int s, input, i, j, num[DIGIT], len; char light[MAX_LEN], unlight[MAX_LEN]; while (scanf("%d %d", &s, &input) != EOF) { memset(light, '-', s); memset(unlight, ' ', s); light[s] = unlight[s] = '\0'; for (len=-1; input; input /= 10) num[++len] = input % 10; for (j=len; j>=0; --j) printf(" %s %c", seg[num[j]][0]?light:unlight, j ? ' ' : '\n'); for (i=0; i<s; ++i) for (j=len; j>=0; --j) printf("%c%s%c%c", seg[num[j]][1]?'|':' ', unlight, seg[num[j]][2]?'|':' ', j ? ' ' : '\n'); for (j=len; j>=0; --j) printf(" %s %c", seg[num[j]][3]?light:unlight, j ? ' ' : '\n'); for (i=0; i<s; ++i) for (j=len; j>=0; --j) printf("%c%s%c%c", seg[num[j]][4]?'|':' ', unlight, seg[num[j]][5]?'|':' ', j ? ' ' : '\n'); for (j=len; j>=0; --j) printf(" %s %c", seg[num[j]][6]?light:unlight, j ? ' ' : '\n'); printf("\n"); } return 0; }