高尔夫代码:数字到单词 [英] Code Golf: Number to Words

查看:85
本文介绍了高尔夫代码:数字到单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码高尔夫系列似乎相当受欢迎.我遇到了一些将数字转换为单词表示形式的代码.一些例子是(2的幂次方为编程带来乐趣):

The code golf series seem to be fairly popular. I ran across some code that converts a number to its word representation. Some examples would be (powers of 2 for programming fun):

  • 2->两个
  • 1024->一千二十四
  • 1048576->一千四百八十五五百七十六

我的同事提出的算法差不多有200行.似乎会有一种更简洁的方法.

The algorithm my co-worker came up was almost two hundred lines long. Seems like there would be a more concise way to do it.

当前准则:

    欢迎以任何编程语言提交的内容(我很抱歉 PhiLho最初对此一无所知)
  • 最大输入量为2 ^ 64(感谢以下单词,请参见以下链接)
  • 短比例尺,英语输出优先,但欢迎使用任何算法.只需连同编程语言一起评论所使用的方法即可.
  • Submissions in any programming language welcome (I apologize to PhiLho for the initial lack of clarity on this one)
  • Max input of 2^64 (see following link for words, thanks mmeyers)
  • Short scale with English output preferred, but any algorithm is welcome. Just comment along with the programming language as to the method used.

推荐答案

Lisp,仅使用标准函数:

Lisp, using only standard functions:

(format nil "~r" 1234) ==> "one thousand two hundred thirty-four"

奖金:

(format nil "~@r" 1234)  ==> "MCCXXXIV"

这篇关于高尔夫代码:数字到单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆