今天的挑战很简单。任务是确定生成提交数据文件的TI计算器。
数据文件总是以字符串**TI、版本(下面描述)和其他可以忽略的数据开始。
现在,您需要识别的版本是:
95* => TI-95
92P => TI-92+
92* => TI-92
89* => TI-89
86* => TI-86
85* => TI-85
84P => TI-84+
84* => TI-84
83* => TI-83
83P => TI-83+
82* => TI-82
81* => TI-81
74* => TI-74
73P => TI-73+**TI95* => TI-95
**TI83P => TI-83+
**TI73P => TI-73+
**TI85* => TI-85
**TI83PGG => TI-83+
**TI86*asdf*9**TI92Pasd => TI-86您可以假设输入总是正确的,至少有7个字符长,并且是为上面列出的TI计算器之一构建的。
这是密码高尔夫,所以最短的答案获胜。
适用I/O规则和漏洞。
发布于 2020-06-15 16:30:11
s;(\d..).*;-$1;;y;P*;+;d保留第一个数字和后面的两个字符,删除之后的任何内容,并在第一个数字之前插入一个-。将任何P替换为+。删除任何*。
从STDIN读取行,将版本写入STDOUT。
准备处理拖着的垃圾。
发布于 2020-06-15 16:31:16
s=>'TI-'+s[4]+s[5]+[{P:'+'}[s[6]]]s => // s = input string: **TIddp[…]
// 0123456
'TI-' + // append the prefix
s[4] + // append the first digit (5th character)
s[5] + // append the second digit (6th character)
[ // wrapper to make sure that undefined is turned into an empty string
{P: '+'} // define an object with a single key 'P' mapped to the value '+'
[s[6]] // and attempt to retrieve this '+', using the 7th character
// (which is either 'P' or '*')
] // end of wrapperhttps://codegolf.stackexchange.com/questions/206158
复制相似问题