=====================================================
//Jessi初学英语,为了快速读出一串数字,编写程序将数字转换成英文:
//如22:twenty two,123:one hundred and twenty three。
//
//说明:
//数字为正整数,长度不超过十位,不考虑小数,转化结果为英文小写;
//输出格式为twenty two;
//非法数据请返回“error”;
//关键字提示:and,billion,million,thousand,hundred。
//
//方法原型:public static String parse(long num)
//
//
//
//知识点 字符串,循环,函数,指针,枚举,位运算,结构体,联合体,文件操作,递归
//运行时间限制 10M
//内存限制 128
//输入
//输入一个long型整数
//输出
//输出相应的英文写法
//样例输入 2356
//样例输出 two thousand three hundred and fifty six
=====================================================
未通过
原因未知 题目问题
========================================================
package package02;
import java.util.Scanner;//Jessi初学英语,为了快速读出一串数字,编写程序将数字转换成英文:
//如22:twenty two,123:one hundred and twenty three。
//
//说明:
//数字为正整数,长度不超过十位,不考虑小数,转化结果为英文小写;
//输出格式为twenty two;
//非法数据请返回“error”;
//关键字提示:and,billion,million,thousand,hundred。
//
//方法原型:public static String parse(long num)
//
//
//
//知识点 字符串,循环,函数,指针,枚举,位运算,结构体,联合体,文件操作,递归
//运行时间限制 10M
//内存限制 128
//输入
//输入一个long型整数
//输出
//输出相应的英文写法
//样例输入 2356
//样例输出 two thousand three hundred and fifty six//个位时没有and
public class oj049 {String[] s1 = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine","ten" }; String[] s2 = { "eleven", "twelve", "thirteen", "forty","fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };String[] s3 = { "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };public String toEnglish(long n){String str="";//if(n==1000000001){str="one billion";return str;} //由评论设计的测试if(n>=1000000000){str+=s1[(int) (n/1000000000-1)]+" "+"billion ";n=n%1000000000; }if(n>=1000000){str+=s1[(int) (n/1000000-1)]+" "+"million ";n=n%1000000; }if(n>=1000){str+=s1[(int) (n/1000-1)]+" "+"thousand ";n=n%1000; }if(n>=100){str+=s1[(int) (n/100-1)]+" "+"hundred";n=n%100; if(n>0){str+=" and ";}}if(n>19){str+=s3[(int) (n/10-2)];n=n%10;if(n!=0) {str+=" ";}}else if(n>10){str+=s2[(int) (n-11)];n=0;}if(n!=0) {str+=s1[(int) (n-1)];}return str;}public static void main(String[] args) {Scanner scanner =new Scanner(System.in);long nLong();if(n<=new Long(999999999)&&n>0){System.out.print(new oj049().toEnglish(n));}else{System.out.print("“error”");}}}
本文发布于:2024-01-30 05:31:52,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170656391419569.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |