@java 蓝 桥 杯 Ejercicios de grupo B ejercicios básicos (30) BASIC-026 asistente de tiempo juicio de condición de cuerda

Descripción del problema

Dada la hora actual, léala en inglés.
  El tiempo se expresa en horas h y minutos M. En la lectura en inglés, la forma de leer una hora es:
  si m es 0, lea la hora, luego agregue "en punto", como 3:00 lea "tres en punto ".
  Si m no es 0, lea el tiempo y luego lea los puntos, como 5:30, lea "cinco y media".
  Las horas y minutos se pronuncian en números ingleses, 0-20 se pronuncia como:
  0: cero, 1: uno, 2: dos, 3: tres, 4: cuatro, 5: cinco, 6: seis, 7: siete, 8: ocho, 9: nueve, 10: diez, 11: once, 12: doce, 13: trece, 14: catorce, 15: quince, 16: dieciseis, 17: diecisiete, 18: dieciocho, 19: diecinueve, veinte y veinte.
  30 se pronuncia treinta, 40 es cuarenta y 50 es cincuenta.
  Para números mayores que 20 y menores que 60, primero lea los diez completos, luego agregue los dígitos individuales. Por ejemplo, 31 lee primero 30 y luego agrega 1, que se lee como "treinta y uno".
  De acuerdo con la regla anterior, 21:54 dice "veintiuno cincuenta y cuatro", 9:07 dice "nueve siete" y 0:15 dice "cero quince".
Formato de
  entrada La entrada contiene dos enteros no negativos h y m, que representan las horas y minutos de tiempo. Los números distintos de cero no tienen ceros a la izquierda. h es menor que 24, m es menor que 60.
Formato de
  salida Hora y hora de salida en inglés.
Entrada de muestra
0 15
Salida de muestra
cero quince


Aquí para compartir con ustedes una solución sin cerebro:

Código:

import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int h=s.nextInt();
		int m=s.nextInt();s.close();
		if(h>=0&&h<24&&m>=0&&m<60) {
			String []shi=new String[] {"zero","one", "two", "three", "four", "five", 
					"six", "seven","eight","nine", "ten", "eleven", "twelve", "thirteen",
					"fourteen","fifteen", "sixteen", "seventeen", "eighteen", "nineteen",
					"twenty","twenty one","twenty two","twenty three"};
			String[]fen=new String[] {
					"zero","one", "two", "three", "four", "five", 
					"six", "seven","eight","nine", "ten", "eleven", "twelve", "thirteen",
					"fourteen","fifteen", "sixteen", "seventeen", "eighteen", "nineteen",
					"twenty","twenty one","twenty two","twenty three","twenty four",
					"twenty five","twenty six","twenty seven","twenty eight","twenty nine",
					"thirty","thirty one", "thirty two", "thirty three", "thirty four", 
					"thirty five","thirty six", "thirty seven","thirty eight","thirty nine",
					"forty","forty one", "forty two", "forty three", "forty four", "forty five", 
					"forty six", "forty seven","forty eight","forty nine","fifty","fifty one",
					"fifty two", "fifty three", "fifty four", "fifty five", "fifty six",
					"fifty seven","fifty eight","fifty nine"};
			if(m==0) {
				System.out.println(shi[h]+" o'clock");
			}else{
				System.out.println(shi[h]+' '+fen[m]);
			}
		}
	}
}
41 artículos originales publicados · Me gusta1 · Visitas1289

Supongo que te gusta

Origin blog.csdn.net/DAurora/article/details/105547159
Recomendado
Clasificación