高尔夫代码:数字到单词

编程入门 行业动态 更新时间:2024-10-10 12:17:07
本文介绍了高尔夫代码:数字到单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

代码高尔夫系列似乎相当受欢迎.我遇到了一些将数字转换为单词表示形式的代码.一些例子是(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"

更多推荐

高尔夫代码:数字到单词

本文发布于:2023-11-29 09:36:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1646027.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单词   高尔夫   代码   数字

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!