显示界面 | HJ64 MP3光标位置
SHOW_LINES = 4 while True: try: n = int(input()) coms = input() if n < SHOW_LINES: # 歌曲数目小于4时,显示行数以实际歌曲数目为准 SHOW_LINES = n c, f = 1, SHOW_LINES # ceiling, floor分别表示所显示最上面和最下面的行号 cur = 1 # 光标位置 for com in coms: if com == 'U': cur -= 1 elif com == 'D': cur += 1 if cur < c: # 光标位置在ceiling以上,需修改ceiling与floor if c != 1: c -= 1 f -= 1 cur = c else: # 翻页,需修改ceiling与floor,并更新光标位置 c = n - SHOW_LINES + 1 f = n cur = f elif cur > f: if f != n: f += 1 c += 1 cur = f else: d = 1 + SHOW_LINES -1 c = 1 cur = c for i in range(c, f+1): print(i, end=' ') print() print(cur) except: break
用时:30min
华为笔试刷题 文章被收录于专栏
高质量题: 1~40:HJ16,HJ22,HJ24,HJ26,HJ27,HJ28,HJ35,HJ37,HJ39; 40~80:HJ41,HJ42,HJ43,HJ44,HJ48,HJ50,HJ52,HJ53,HJ57,HJ61,HJ63,HJ64,HJ70,HJ71,HJ74,HJ77; 80~108:HJ82,HJ85,HJ88,HJ89,HJ93,HJ95,HJ98,HJ103,HJ107