您的任务是计算在旧手机上输入给定文本所需的按键总数。
键映射为:
1:1
2:abcABC2
3:defDEF3
4:ghiGHI4
5:jklJKL5
6:mnoMNO6
7:pqrsPQRS7
8:tuvTUV8
9:wxyzWXYZ9
0:<space><newline>0
要输入exaMPle TExt 01
,您将33 99 2 6666 77777 555 33 0 8888 33333 99 8 0 <a 1-sec pause here in real life but we'll ignore it>000 1
总共按下37次按键。
该*
键将显示一个特殊字符映射:
.,'?!
"-()@
/:_;+
&%*=<
>£€$¥
¤[]{}
\~^¡¿
§#|`
并.
突出显示第一个()。您可以使用矩形导航键移动以突出显示所需的字符,然后再次按下该键即可选择。
因此,要插入$
,您将按,*↓↓↓↓→→→<select>
即总共9次按键。
- 输入将来自位于程序
source
当前目录中的一个文件。 编辑:根据注释中的请求,我添加STDIN
为有效的输入法。抱歉,在收到答案后更改规格。 - 您必须输出
Total key presses <total_keypresses>
- 如果输入文件包含给定键映射中没有的任何字符,则您的程序必须输出
Invalid character <character> in source
并退出。
简而言之,您的程序的输入和输出必须类似于以下(已解冻的)python脚本的输入和输出:
# This Python file uses the following encoding: utf-8
from __future__ import print_function
import sys
general_dict = { '1':1,
'a':1, 'b':2, 'c':3, 'A':4, 'B':5, 'C':6, '2':7,
'd':1, 'e':2, 'f':3, 'D':4, 'E':5, 'F':6, '3':7,
'g':1, 'h':2, 'i':3, 'G':4, 'H':5, 'I':6, '4':7,
'j':1, 'k':2, 'l':3, 'J':4, 'K':5, 'L':6, '5':7,
'm':1, 'n':2, 'o':3, 'M':4, 'N':5, 'O':6, '6':7,
'p':1, 'q':2, 'r':3, 's':4, 'P':5, 'Q':6, 'R':7, 'S':8, '7':9,
't':1, 'u':2, 'v':3, 'T':4, 'U':5, 'V':6, '8':7,
'w':1, 'x':2, 'y':3, 'z':4, 'W':5, 'X':6, 'Y':7, 'Z':8, '9':9,
' ':1, '\n':2, '0':3
}
special_chars = ['.',',',"'",'?','!','"','-','(',')','@','/',':','_',';','+','&','%','*','=','<','>','£','€','$','¥','¤','[',']','{','}','\\','~','^','¡','¿','§','#','|','`']
for x in special_chars:
general_dict[x]=(special_chars.index(x)/5) + (special_chars.index(x)%5) + 2
key_press_total = 0
with open('source') as f: # or # with sys.stdin as f:
for line in f:
for character in line:
if character in general_dict:
key_press_total+=general_dict[character]
else:
print('Invalid character',character,'in source')
sys.exit(1)
print('Total key presses',key_press_total)
这是代码高尔夫球,最短的程序以字节为单位。
1ce5a2fdd0316e37c0a07d151d02db766a3adbb7
。