蓝桥杯 1468: [蓝桥杯][基础练习VIP]报时助手

基本思想:

水题,没什么可说的;

 

关键点:

无;

 

#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector> 
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;

vector<string>time_1 = {"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"};
vector<string>time_2 = { "twenty","thirty","forty","fifty" };

string func(int n) {
	if (n <= 20)
		return time_1[n];
	int m = n % 10;
	n = n / 10-2;
	string s = time_2[n];
	if (m != 0)
		s += ' ' + time_1[m];
	return s;
}

int main(){
	int h, m;
	cin >> h >> m;
	if (m == 0)
		cout << func(h) << " o'clock";
	else
		cout << func(h) << " " << func(m);
	return 0;
}

  

posted @ 2020-02-09 14:15  暮云林凌  阅读(199)  评论(0)    收藏  举报