问题很简单。给定一个字符串(如Hello World! ),程序将输出8-5-12-12-15 23-15-18-12-4-!。任何分隔符都可以,(请指定它们是什么)我只是选择在单词之间使用空格,在字符之间使用破折号。
转换是将所有字母字符转换为它们的数字等价物。即A=1,B=2,...,Z=26.所有其他字符必须保持原样。对案件不敏感。另一个例子
Here's another example, I hope that this will illustrate my point! If it's unable, more specs will be given.
8-5-18-5-'-19 1-14-15-20-8-5-18 5-24-1-13-16-12-5-, 9 8-15-16-5 20-8-1-20 20-8-9-19 23-9-12-12 9-12-12-21-19-20-18-1-20-5 13-25 16-15-9-14-20-! 9-6 9-20-'-19 21-14-1-2-12-5-, 13-15-18-5 19-16-5-3-19 23-9-12-12 2-5 7-9-22-5-14-.注意,字符之间没有尾随或开始分隔符。
评分将基于最短的代码数量。任何语言都是欢迎的。
只要有更多的答案,我就会改变胜利者。GLHF!
发布于 2013-08-07 17:10:38
在那里,现在它符合更新的规则并使输出更加美观。
gsub(/\w+/){A2.chars.map{|c|c.ord&31}*?-}使用-p开关运行:
ruby -p ord.rb <<< "ABC! Defghi, jklmnopqr stuvwxyz"
1-2-3! 4-5-6-7-8-9, 10-11-12-13-14-15-16-17-18 19-20-21-22-23-24-25-26发布于 2013-08-09 07:08:20
有点太长了,无法真正参与竞争,但我们现在开始:
s=sapply
l=letters
cat(s(strsplit(scan(,""),""),function(x)paste(s(tolower(x),function(y)ifelse(y%in%l,which(l==y),y)),collapse="-")))字分隔符是空格,字符定界符是-。
发布于 2013-08-08 10:30:15
用作分隔符的逗号。
If[64 < # < 97, # - 64, FromCharacterCode@#] & /@ ToCharacterCode@ToUpperCase@ii="To be, or not to be,--that is the question:-- Whether 'tis nobler in
the mind to suffer The slings and arrows of outrageous fortune Or to
take arms against a sea of troubles, And by opposing end them?";
If[64 < # < 97, # - 64, FromCharacterCode@#] & /@ ToCharacterCode@ToUpperCase@i{20、15、“、2、5、”、15、18、“、14、15、20、”、20、15、“、2、5、”、"-“、"-”-“、20、8、1、20、”、“、9、19、”、“、20、8、5、”、“、17、21、5、19、20、9、15、14、”"-“、23、8、5、20、8、5、18、”、20、9、19、“、14、15、2、12、5、18、”、“、9、14、”、“、20、8、5、”、“、13、9、14、4、”、“、20、15、”、19、21、6、6、5、18、“、20、8、5、5、“、”、19、12、9、14、7、19、“、1、14、4、”、“、1、18、18、15、23、19、”、15、6、“、15、21、20、18、1、7、5、15、21、19、”、6、15、18、20、21、14、5、“”、15、18、“、20、15、15、5”、20、1、11、5、“、1、18、13、19、”、1、7、1、9、14、19、20、“、1、”、19、5、1、“、”、15、6、“、20、18、15、21、2、12、5、19、”、1、14、4、“、”、2、25、“、15、16、16、15、19、9、14、7、5,14,4,“",20,8,5,13,”?“
https://codegolf.stackexchange.com/questions/12253
复制相似问题