华为OJ训练之0049

阅读: 评论:0

华为OJ训练之0049

华为OJ训练之0049

=====================================================

//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 n&#Long();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小时内删除。

标签:华为   OJ
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23