2 条题解
-
0
算法标签:
搜索 dfs
题解:
液晶数字的段结构:每个数字由 7 个段组成,具体如下: segment [0]:顶部水平段 segment [1]:右上垂直段 segment [2]:左上垂直段 segment [3]:中部水平段 segment [4]:左下垂直段 segment [5]:右下垂直段 segment [6]:底部水平段 各数字点亮的段:不同数字在 LC 显示中点亮的段编号如下: 数字 0:点亮段 [0, 1, 2, 4, 5, 6] 数字 1:点亮段 [1, 5] 数字 2:点亮段 [0, 1, 3, 4, 6] 数字 3:点亮段 [0, 1, 3, 5, 6] 数字 4:点亮段 [1, 2, 3, 5] 数字 5:点亮段 [0, 2, 3, 5, 6] 数字 6:点亮段 [0, 2, 3, 4, 5, 6] 数字 7:点亮段 [0, 1, 5] 数字 8:点亮段 [0, 1, 2, 3, 4, 5, 6] 数字 9:点亮段 [0, 1, 2, 3, 5, 6] 显示区域构造方法: 使用一个 vector 来保存完整显示内容的每一行。 按照每个数字在输入中的位置,将该数字对应的每个段画到显示区域中。 对于水平段(段 0、3、6):在显示区域中填充 s 个 - 字符。 对于垂直段(段 1、2、4、5):在显示区域中填充 s 行的 | 字符。
#include<iostream> using namespace std; /* ---- //b[0] | | | | | | //c[0][2] | | ---- //b[1] | | | | // c[1][2] | | | | ---- //b[2] 如上图,是一个数字的基本框架,可以为分2类,输出‘-’部分(行)、‘|’部分(多行)。 下面的b数组是用来描述‘-’部分的有无, c数组是用来描述‘|’部分的有无。 */ int b[3][10] = { {1, 0, 1, 1, 0, 1, 1, 1, 1, 1}, {0, 0, 1, 1, 1, 1, 1, 0, 1, 1}, {1, 0, 1, 1, 0, 1, 1, 0, 1, 1} }; int c[2][10][2] = { {{1, 1}, {0, 1}, {0, 1}, {0, 1}, {1, 1}, {1, 0}, {1, 0}, {0, 1}, {1, 1}, {1, 1}}, {{1, 1}, {0, 1}, {1, 0}, {0, 1}, {0, 1}, {0, 1}, {1, 1}, {0, 1}, {1, 1}, {0, 1}} }; int s, n; int digit[20]; void f(int a[], int n) { int i,j,k; for(i=1; i<=n; i++) { cout<<' '; for(j=0; j<s; j++) if(a[digit[i]] == 1) cout<<'-'; else cout<<' '; cout<<' '; if(i != n) cout<<' '; } cout<<endl; } void g(int a[][2], int n) { int i,j,k; for(i=1; i<=n; i++) { if(a[digit[i]][0] == 1) cout<<'|'; else cout<<' '; for(j=0; j<s; j++) cout<<' '; if(a[digit[i]][1] == 1) cout<<'|'; else cout<<' '; if(i != n) cout<<' '; } cout<<endl; } int main() { int dec[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000}; while(cin>>s>>n && s*s+n*n != 0) { int i,j,k; int count = 0; for(i=1; i<=8 && count == 0; i++) if(n < dec[i]) count = i; for(i=1; i<=count; i++) { digit[i] = n/dec[count-i]; n = n%dec[count-i]; } f(b[0], count); for(i=0; i<s; i++) g(c[0], count); f(b[1], count); for(i=0; i<s; i++) g(c[1], count); f(b[2], count); cout<<endl; } return 0; }
-
0
🧠 题解 本题是一道模拟题,关键在于 用字符模拟 LC 液晶数字的显示结构,需要注意的是:
✅ 每个数字对应的 7 个段如下(命名为 segment): less 复制 编辑 -- segment[0](顶部水平) | | segment[1](右上) 和 segment[2](左上) -- segment[3](中部水平) | | segment[4](左下) 和 segment[5](右下) -- segment[6](底部水平)
✅ 每个数字在 LC 显示中点亮的段如下(段编号从上到下,从左到右为 0~6): 数字 点亮段编号(segment)
✅ 构造方法: 使用一个 vector 保存完整显示内容的每一行;
按照每个数字的位置,将该数字的每个段画上去;
对每个段:
水平段(段 )填充 个 -;
垂直段(段 )填充 行的 |;
最后,每组输出结束后输出一个空行。
✅ 注意事项: 每个数字之间要有一列空格;
输入终止条件为 0 0;
如果 ,也要显示对应的 LC 风格,不可省略;
显示区域的大小与 有关,行数为 ,列数为 ;
要正确处理所有数字的行拼接与段点亮情况。
代码实现:
#include <cstdio> #include <cstring> using namespace std; int s; char n[20],eight[35][20],str[35][20]; void printblank(){ for(int i=0;i<2*s+3;i++) printf(" \n"); } void createight(){ memset(eight,0,sizeof(eight)); eight[0][0]=' '; for(int j=1;j<s+1;j++) eight[0][j]='-'; eight[0][s+1]=' '; for(int i=1;i<s+1;i++){ eight[i][0]='|'; for(int j=1;j<s+1;j++) eight[i][j]=' '; eight[i][s+1]='|'; } eight[s+1][0]=' '; for(int j=1;j<s+1;j++) eight[s+1][j]='-'; eight[s+1][s+1]=' '; for(int i=s+2;i<2*s+2;i++){ eight[i][0]='|'; for(int j=1;j<s+1;j++) eight[i][j]=' '; eight[i][s+1]='|'; } eight[2*s+2][0]=' '; for(int j=1;j<s+1;j++) eight[2*s+2][j]='-'; eight[2*s+2][s+1]=' '; } void clear(int p){ if(p==1) for(int j=0;j<s+2;j++) str[0][j]=' '; else if(p==2) for(int i=1;i<s+1;i++) str[i][0]=' '; else if(p==3) for(int i=1;i<s+1;i++) str[i][s+1]=' '; else if(p==4) for(int j=0;j<s+2;j++) str[s+1][j]=' '; else if(p==5) for(int i=s+2;i<2*s+2;i++) str[i][0]=' '; else if(p==6) for(int i=s+2;i<2*s+2;i++) str[i][s+1]=' '; else if(p==7) for(int j=0;j<s+2;j++) str[2*s+2][j]=' '; } void copy(){ for(int i=0;i<2*s+3;i++){ for(int j=0;j<s+2;j++) str[i][j]=eight[i][j]; } } void print(int x){ copy(); if(x==1){ clear(1); clear(2); clear(4); clear(5); clear(7); } else if(x==2){ clear(2); clear(6); } else if(x==3){ clear(2); clear(5); } else if(x==4){ clear(1); clear(5); clear(7); } else if(x==5){ clear(3); clear(5); } else if(x==6){ clear(3); } else if(x==7){ clear(2); clear(4); clear(5); clear(7); } else if(x==9){ clear(5); } else if(x==0){ clear(4); } } int main() { //freopen("cin.txt","r",stdin); while(cin>>s>>n){ if(s==0&&n[0]=='0') break; createight(); int length=strlen(n); int i,j,k; for(i=0;i<2*s+3;i++){ for(k=0;k<length;k++){ print(n[k]-'0'); for(j=0;j<s+2;j++) printf("%c",str[i][j]); printf(" "); } puts(""); } puts(""); } return 0; }
- 1
信息
- ID
- 103
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者