XKCD:键盘混搭异常


16

另一个XKCD启发的比赛。这是基于Keyboard Mash的

给定一个输入字符串,假定大多数字符已在标准US QWERTY键盘的单行上键入,请识别出异常字符。输入字符串可以包含移位的击键,但它们不包含回车键(Enter),受CTRL / ALT影响的字符,空格,制表符和退格键(因为这样做很愚蠢)。数字键盘将不被视为此挑战的键盘一部分。

挑战在于输出与单个字符串中大多数单个字符不在同一键盘行上的字符。输出应仅包含每个异常字符一次,并且不包含其他字符。

如果两行或更多行中的异常字符数相等,则按以下顺序确定抢七局:

  • 最短的唯一列表
  • 最上一行

输入值

通过STDIN,ARGV或函数参数的字符串

输出量

STDOUT的字符串或函数返回。每个异常字符应该只出现一次,但是不需要排序。

例子

输入: FJAFJKLDSKF7KFDJ
输出: 7

输入: ASDF11111
输出: ASDF

输入: lkjrhsDdftkjhrksRjd
输出: rtR

输入: } * 3%&2098 @ $ 2k234#@ $ M
输出: }

返回最上面的行列表
输入: ASD!@#Vcx
输出:!@#

返回的最短唯一列表
输入: ASdf1233qwER
输出: 123

返回的最短最短列表
输入: 12334QWTTSDFDSXVVBBX
输出: QWT

这是代码高尔夫球,因此最短的入场券获胜。

Answers:


8

CJam,111 89 88 86 84 83字节

la9*~"{}qwertyuiop ;':asdfghjkl ,./<>?zxcvbnm"{_32^}%_'ÿ,^a\S%+{[f&s\e|__|]:,}$0=&

CJam解释器中在线尝试。

怎么运行的

la9*~     e# Push the input 9 times on the stack.

"{}qwertyuiop ;':<STX>asdfghjkl ,./<>?zxcvbnm"

{_32^}%   e# XOR a copy of each character with 32.
_'<DEL>,^ e# Push a string of all ASCII characters that are missing.
a\        e# Wrap it in an array.
S%+       e# Split the string at spaces and concatenate with the array.
{         e# Sort the chunks according to the following:
  [       e#
    f&s   e# Push the string of characters from the input that are in this chunk.
    \e|   e# If the result is empty, replace it with the input.
    __|   e# Push a copy with duplicates removed.
  ]       e# Collect both strings in an array.
  :,      e# Replace each string with its length.
}$        e#
0=        e# Retrieve the minimum.
&         e# Intersect it with the input.

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.