解题思路:把庚子年作为开始年,每过60年一个循环
注意事项:正年数与负年数方向不一样(2019 是己亥年 2021是辛丑年)都与2020差一年
参考代码:
#include <iostream> #include <algorithm> #include <cstdio> #include <string> using namespace std; string tian_gan[10]={"geng","xin","ren","gui","jia","yi","bing","ding","wu","ji"}; string di_zi[12]={"zi","chou","yin","mao","chen","si","wu","wei","shen","you","xu","hai"}; int main() { int y,n; cin>>y; n=(y-2020)%60; if(n>=0) // 如果年数是正整数从前往后找 cout<<tian_gan[n%10]<<di_zi[n%12]<<endl; else // 负整数从后往前找 cout<<tian_gan[10+n%10]<<di_zi[12+n%12]<<endl; return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题11.8 (C语言代码)浏览:910 |
2006年春浙江省计算机等级考试二级C 编程题(2) (C语言代码)浏览:503 |
小九九 (C语言描述,不看要求真坑爹)浏览:1006 |
C二级辅导-阶乘数列 (C语言代码)浏览:583 |
输入输出格式练习 (C语言代码)浏览:773 |
【魔板】 (C++代码)浏览:1236 |
快速排序算法1浏览:996 |
C二级辅导-等差数列 (C语言代码)浏览:831 |
C语言程序设计教程(第三版)课后习题8.4 (C++代码)浏览:472 |
简单的a+b (C语言代码)浏览:667 |