前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >蓝桥杯 试题 基础练习 报时助手

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

作者头像
杨鹏伟
发布2020-09-11 15:09:28
3400
发布2020-09-11 15:09:28
举报
文章被收录于专栏:ypw

map用法 水题

代码语言:javascript
复制
#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;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/03/05 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档