整活实现数字记分牌
Posted 麒思妙想
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了整活实现数字记分牌相关的知识,希望对你有一定的参考价值。
最近在学习南京大学的操作系统课程,老师展现了一下记分牌只显示了0,1,2 而且是C写的,转成java的玩一下,还挺有意思。。。。
public class Main
static int[][] datas = new int[][]
1,1,1,1,1,1,0,
0,1,1,0,0,0,0,
1,1,0,1,1,0,1,
1,1,1,1,0,0,1,
0,1,1,0,0,1,1,
1,0,1,1,0,1,1,
1,0,1,1,1,1,1,
1,1,1,0,0,0,0,
1,1,1,1,1,1,1,
1,1,1,1,0,1,1
;
public static void main(String[] args) throws InterruptedException
int i = 0;
while(true)
if(i>=datas.length)
i = 0;
System.out.println(String.format("A = %d; B = %d; C = %d; D = %d; E = %d; F = %d; G = %d;",datas[i][0],datas[i][1],datas[i][2],datas[i][3],datas[i][4],datas[i][5],datas[i][6]));
i++;
Thread.sleep(1000);
import fileinput
TEMPLATE = '''
\\033[2J\\033[1;1f
AAAAAAAAA
FF BB
FF BB
FF BB
FF BB
GGGGGGGGGG
EE CC
EE CC
EE CC
EE CC
DDDDDDDDD
'''
BLOCK =
0: '\\033[37m░\\033[0m', # STFW: ANSI Escape Code
1: '\\033[31m█\\033[0m',
VARS = 'ABCDEFG'
for v in VARS:
globals()[v] = 0
stdin = fileinput.input()
while True:
exec(stdin.readline())
pic = TEMPLATE
for v in VARS:
pic = pic.replace(v, BLOCK[globals()[v]]) # 'A' -> BLOCK[A], ...
print(pic)
运行:
java Main | python3 seven-seg.py
结果
以上是关于整活实现数字记分牌的主要内容,如果未能解决你的问题,请参考以下文章