蓝桥杯VIP试题 基础练习 报时助手

蓝桥杯VIP试题 基础练习 报时助手,第1张

蓝桥杯VIP试题 基础练习 报时助手

 

输入格式

  输入包含两个非负整数h和m,表示时间的时和分。非零的数字前没有前导0。h小于24,m小于60。

输出格式

  输出时间时刻的英文。

样例输入

0 15

样例输出

zero fifteen

package VIP;

import java.util.Scanner;

public class 报时助手 {
     static String x[]= {"zero", "one", "two", "three","four", "five","six","seven", "eight","nine"};
     static String y[]= {"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"};
     static String z[]= {"twenty","thirty","forty","fifty"};
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int h=sc.nextInt();
		int m=sc.nextInt();
       Translation(h, m); 
	}
	public static void Translation(int h,int m) {
		if (h<10) {
			System.out.print(x[h%10]+" ");
		}
		if (h>=10&&h<20) {
			System.out.print(y[h%10]+" ");
		}
		if (h>=20&&h<24) {
			if (h%10==0) {
				System.out.print(z[h/10-2]+" ");
			}else
			System.out.print(z[h/10-2]+" "+x[h%10]+" ");
		}
		
		if(m!=0) {
		   if (m<10) {
			System.out.print(x[m%10]+" ");
		}
		if (m>=10&&m<20) {
			System.out.print(y[m%10]+" ");
		}
		if (m>=20&&m<60) {
			if (m%10==0) {
				System.err.print(z[m/10-2]+" ");
			}else
			System.out.print(z[m/10-2]+" "+x[m%10]+" ");
		}
		}
		else {
		System.out.print("o'clock");	
		}
		System.out.println();
	
	}
}

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5712388.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存