欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-03-14 09:49:37
...

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

#include<iostream>
#include<string>
#include<map>

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;
}

c++98 里不用unordered_map,也不能用{}来初始化map

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

相关标签: hash