Perl 78字节
map{push$_[keys{map{$_,1}/./g}]||=[],$_}split for<>;print"$_ $#_
"for@{$_[-1]}
解释此限制“文本文档必须由您的代码读取”,表示不允许读取和解析输入的命令行选项。与下面的PHP解决方案一样,仅将字符10和32视为单词定界符。输入和输出也以相同的方式进行。
PHP 128字节
<?foreach(split(~߃õ,fread(STDIN,1e6))as$s){$w[count(count_chars($s,1))][]=$s;}krsort($w)?><?=join($f=~ß.key($w).~õ,pos($w)),$f;
唯一被认为是单词定界符的字符是字符10和字符32。其余的字符(包括标点符号)被认为是单词的一部分。
它包含一些二进制字符,这些字符保存引号,但是结果需要使用ANSI编码保存才能正常运行。或者,可以使用此版本,该版本重3个字节:
<?foreach(split(' |
',fread(STDIN,1e6))as$s){$w[count(count_chars($s,1))][]=$s;}krsort($w)?><?=join($f=' '.key($w).'
',pos($w)),$f;
样本I / O:
输入1:
It was the best of times, it was the worst of times, it was the age of wisdom,
it was the age of foolishness, it was the epoch of belief, it was the epoch of
incredulity, it was the season of Light, it was the season of Darkness, it was
the spring of hope, it was the winter of despair, we had everything before us,
we had nothing before us, we were all going direct to Heaven, we were all going
direct the other way - in short, the period was so far like the present period,
that some of its noisiest authorities insisted on its being received, for good
or for evil, in the superlative degree of comparison only.
输出1:
$ php most-unique.php < input1.dat
incredulity, 11
输入2:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec mollis, nisl sit
amet consequat fringilla, justo risus iaculis justo, vel ullamcorper dui tellus
ut enim. Suspendisse lectus risus, molestie sed volutpat nec, eleifend vitae
ligula. Nulla porttitor elit vel augue pretium cursus. Donec in turpis lectus.
Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia
Curae; Quisque a lorem eu turpis viverra sodales. Pellentesque justo arcu,
venenatis nec hendrerit a, molestie vitae augue.
输出2:
$ php most-unique.php < input2.dat
consequat 9
ullamcorper 9
Vestibulum 9