最近在学习南京大学的 *** 作系统课程,老师展现了一下记分牌只显示了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
结果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)