首页 > 试题广场 >

学英语

[编程题]学英语
  • 热度指数:125797 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
\hspace{15pt}你需要编写一个程序,使得对于输入的整数,输出其对应的英文单词。

\hspace{15pt}具体地,规则如下:
{\hspace{20pt}}_\texttt{1.}\,三位数字看成一整体,每三位数后添加一个计数单位,从小到大依次为 thousand(千)、million(百万);
{\hspace{20pt}}_\texttt{2.}\,对于百万以下、千以上的数字,通用公式为 x \textrm{ thousand } y ,其中 xy 代表数字;
{\hspace{20pt}}_\texttt{3.}\,对于百万以上的数字,通用公式为 x \textrm{ million } y \textrm{ thousand } z ,其中 xyz 代表数字;
{\hspace{20pt}}_\texttt{4.}\,每三位数内部,十位和个位之间,需要添加 and ;特别地,若百位为 0 ,则不添加。例如,1\,234 的英文为 one thousand two hundred and thirty four ,1\,034 的英文为 one thousand thirty four 。

\hspace{15pt}让我们再来看几个例子:
\hspace{23pt}\bullet\,22:twenty two ;
\hspace{23pt}\bullet\,100:one hundred
\hspace{23pt}\bullet\,145:one hundred and forty five ;
\hspace{23pt}\bullet\,1\,234:one thousand two hundred and thirty four ;
\hspace{23pt}\bullet\,8\,088:eight thousand eighty eight ;
\hspace{23pt}\bullet\,486\,669:four hundred and eighty six thousand six hundred and sixty nine ;
\hspace{23pt}\bullet\,1\,652\,510:one million six hundred and fifty two thousand five hundred and ten 。

输入描述:
\hspace{15pt}在一行上输入一个整数 n \left(1 \leqq n \leqq 2 \times 10^6\right) 代表待转换的整数。


输出描述:
\hspace{15pt}输出若干个小写的英文单词,代表转换后的结果。
示例1

输入

22

输出

twenty two
示例2

输入

2000000

输出

two million
头像 牛客155969019号
发表于 2021-10-16 18:28:09
num1 = ['zero','one','two','three','four','five','six', 'seven','eight','nine','ten','eleven','twelve', 'thirteen','fourteen','fifteen', 展开全文
头像 牛客199629370号
发表于 2021-02-13 14:27:29
对于本题,需要找出重复性,按照英文数字的范围,每三位隔一次,如000,000,000,由于范围已经限定在9位以内,同时,每三位就相当于一个范围,即百万、千,那么,最后的递归只要找到三位以内的判断 import java.util.*; public class Main{ public 展开全文
头像 陶陶2021
发表于 2021-10-06 23:11:41
1、小于20的直接读数,如果个位和十位是0,则不需要读数(正百的100,例:one hundred);如果有百位读取百位,如果个位和十位是0,则不需要加and,否则需要加and,加hubdred,加百位 2、大于20的,依次添加个位,十位,百位;添加百位的时候,先加and,加hundred,加百位 展开全文
头像 _becky
发表于 2022-03-21 20:07:14
#include<bits/stdc++.h> using namespace std; string ones[] = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; 展开全文
头像 蓝域小兵
发表于 2020-09-04 20:25:22
#include <bits/stdc++.h> using namespace std; vector<string> other = {"zero","one","two","three","four", \ "five","six","seven","ei 展开全文
头像 你敲代码的样子好像蔡徐坤
发表于 2021-09-26 22:31:02
#include<bits/stdc++.h> using namespace std; string englishnum(int num) { vector<string> other = {"zero", "one", 展开全文
头像 mosh
发表于 2022-04-22 08:03:36
#include <stdio.h> static char base[][10] = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve" 展开全文
头像 菲鸽爱编程
发表于 2022-03-29 11:52:18
const ones = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine'] const tens = [ 'ten', 'eleven', 'twelve', 'thirt 展开全文
头像 信雪神话
发表于 2022-02-14 11:01:29
输入数据小于2000000,所以热门大佬的代码可以简化 num1 = ['zero','one','two','three','four','five','six', 'seven','eight','nine','ten','eleven','twelve', 'thi 展开全文
头像 法拉利201903231900848
发表于 2019-08-19 16:46:56
#有些地方还有些迷糊,先MARK一下 def dps(n):     m1 = 'one,two,three,four,five,six,seven,eight,nine,ten,eleven,twelve,thirteen,fo 展开全文

问题信息

难度:
309条回答 34362浏览

热门推荐

通过挑战的用户

学英语