C 中的古代日本日历练习
Ancient Japanese calendar exercise in C++
练习:
在古代日本日历中是60年的周期。每年的数量从1到60,分为成对,每种都有自己的颜色(绿色,红色,黄色,白色或黑色)。年度的颜色分布如下:
- 1,2,2,11,12,21,22,...,51,52年 - 绿色;
- 3,4,13,14,23,24,...,53,54年 - 红色;
- 5、6、6、15、16、25、26,...,55、56年 - 黄色;
- 7、8、17、18、27、28,...,57、58年 - 白色;
- 9、10、19、20、29、30,...,59、60年 - 黑色。
我们知道,新的60年周期始于1984年,将于2043年结束;1984年和1985年是绿色年,1986年和1987年是红色年,2043年将是黑色年。
我们知道年 m (1800< m< 2200)。编写一个程序,打印出年度的颜色。
P.S。此练习不是用英语写的!
根据您的列表,颜色在10年周期内旋转,然后以相同的颜色始终具有2个随后的几年。鉴于该规则您可以在年度颜色的字段中计算索引。
#include <vector>
#include <string>
#include <iostream>
using namespace std;
int main()
{
const int base_year = 1984;
vector<string> colors = { "green", "red", "yellow", "white", "black" };
int year;
cout << "Insert year: ";
cin >> year;
int offset = year - base_year;
int index = (offset % 10) / 2;
if (index < 0) index += colors.size();
cout << "year offset " << offset << " color index :" << "year color: " << colors[index] << endl;
return 0;
}
相关文章:
- Gtkmm 会不断检查 Gtk::日历上的所选日期是否发生变化
- 从编译时已知的日历日期创建"std::chrono::time_point"
- 从谷歌日历API获取错误请求
- 如何在不使用 std::tm 和 mktime() 的情况下为给定日历日期创建 chrono::time_point 对
- 如何在Mac OSX中获取真实的日历微秒时间(自1970年以来的纪元)?
- 带有日本字符的CPPREST?
- C++日历(无法获取变量的值以返回到主函数)
- 为什么周一周一上午3点更新日历周的数字,但不是在午夜
- 日历时间,纳秒分辨率为纳秒纪元
- C++谷歌日历API
- 根据朱利安日历计算月份
- 如何在没有错误的情况下展示特殊的中文,韩语,日本角色
- C ICU库如何确定要缓存的日历对象
- C 中的古代日本日历练习
- "日期":'class'类型重新定义:错误(日历.cpp文件错误)
- 为什么C STD :: String可以支持日本的角色,法语
- 如何将具有功能的日历程序输出到.txt文件
- 坚持认为学校的C 日历代码
- 如何将标准::时间::time_point转换为带有秒小数部分的日历日期时间字符串?
- 如何在Windows日历控件上设置字体