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

map用法
水题

#include<bits/stdc++.h>

using namespace std; 

int main()
{
	pair<int,string>temp[] = {{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,"thirty"},{40,"forty"},
		{50,"fifty"},{60,"sixty"}};
	map<int,string>hash;
	for(int i = 0; i < 25; i++)
	{
		hash[temp[i].first] = temp[i].second;
	}
	int h,m;
	cin>>h>>m;
	if(h > 20)
	{
		cout<<hash[20]<<" "+hash[h%20]<<" ";
	}
	else
	{
		cout<<hash[h]<<" ";
	}
	if(m == 0)
	{
		cout<<"o'clock";
	}
	else
	{
		if(m > 20)
		{
			int mod = m%10;
			m = m - mod;
			cout<<hash[m]<<" "<<hash[mod];
		}
		else
		{
			cout<<hash[m];
		}
	}
	return 0;
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值