Basic exercises - timekeeping assistant


title: basic exercises timekeeping assistant
categories:

  • ACM
  • Water title
    tags:
  • An array of strings
    date: 2020-03-12 10:12:49

Since 0 to 23 have the full string, the tens digit 20,30,40,50 to be continuously stored, they demand plus an offset

problem

Questions basic training timekeeping assistant

By submitting this question

Resource constraints

Time limit: 1.0s Memory Limit: 512.0MB

Problem Description

Given the current time, please read in English law it will be read out.
  When using the time points h and m represent, in the English reading process, a read time is:
  if m is 0, then read out, and then add "o'clock", such as 3:00 read as "three o'clock ".
  If m is not 0, then read out, and then read out the points, such as 5:30 read as "five thirty".
  Using the hour and minute reading of English digital readings, wherein 0 to 20 read as:
  0: ZERO,. 1: One, 2: TWO,. 3: Three,. 4: Four,. 5: Five,. 6: Six, 7: seven, 8: eight, 9: nine, 10: ten, 11: eleven, 12: twelve, 13: thirteen, 14: fourteen, 15: fifteen, 16: sixteen, 17: seventeen, 18: eighteen, 19: nineteen, 20: twenty.
  30 read as thirty, 40 read as forty, 50 read as fifty.
  Greater than 20 to less than 60 in number, the number of first read the entire ten, then add digits. The 30 plus 31 first reads a reading method of reading as "thirty one".
  According to the above rules 21:54 read as "twenty one fifty four", 9 : 07 read as "nine seven", 0: 15 read as "zero fifteen".

Input Format

Input contains two non-negative integers h and m, indicates hours and minutes of time. No leading zero before the number 0. h is less than 24, m is less than 60.

Output Format

English output moments in time.

Sample input

0 15

Sample Output

zero fifteen

algorithm

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
#include<map>
#define PI 3.14159265358979323
#define MAX 0x3f3f3f3f
using namespace std;
int main(){
	//freopen("input.txt", "r", stdin);
	string yingshe[]={"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","thirty","forty","fifty"}; 
	int h,m;
	cin>>h>>m;
	cout<<yingshe[h]<<" ";
	if(m==0)
	{
		cout<<"o'clock";
		
	}
	else if(m>0&&m<=23)
	cout<<yingshe[m];
	else
	{
		int s=m/10+2;
		int g=m%10;
		cout<<yingshe[20+s]<<" "<<yingshe[g];
	}
	return 0;	
}
Published 43 original articles · won praise 1 · views 923

Guess you like

Origin blog.csdn.net/qq_43985303/article/details/104865506