解题思路:通过题意计算出第0年的纪年来作为初始值
注意事项:
参考代码:
#include<iostream> using namespace std; int main(){ string tiangan[10]={"jia","yi","bing","ding","wu","ji","geng","xin","ren","gui"}; string dizhi[12]={"zi","chou","yin","mao","chen","si","wu","wei","shen","you","xu","hai"}; int n,tstar=6,dstar=8; cin>>n; n%=60; cout<<tiangan[(n%10+tstar)%10]<<dizhi[(n%12+dstar)%12]; return 0; }
0.0分
3 人评分
#include<iostream> using namespace std; string tian[10] = {"geng","xin","ren","gui","jia","yi","bing","ding","wu","ji"}; string di[12] = {"zi","chou","yin","mao","chen","si","wu","wei","shen","you","xu","hai"} ; int main() { int n; cin>>n; if(n>0) { //2020年是庚子年 int d = n>2020?(n-2020):(2020-n); int a = d%10; int b = d%12; cout<<tian[a]<<di[b]; } return 0; } //可以看看我的
liuzhendong 2024-01-26 14:06:22 |
我是把庚子分别放到数组的第一个,然后对10和对12的余数作为偏移量,因为庚子是第一个所以这个就是下标
大佬们,请问怎么理解tstar=6和dstar=8呀?
笔盖大失 2022-04-01 23:49:02 |
天干初始在下标为6的地方即 庚 同理,初始地支在下标为8的地方即 申
叮叮咚咚嗒 2022-04-02 14:02:22 |
好的,谢谢
liuzhendong 2024-01-26 14:04:10 |
#include<iostream> using namespace std; string tian[10] = {"geng","xin","ren","gui","jia","yi","bing","ding","wu","ji"}; string di[12] = {"zi","chou","yin","mao","chen","si","wu","wei","shen","you","xu","hai"} ; int main() { int n; while(cin>>n) if(n>0) { //2020年是庚子年 int d = n>2020?(n-2020):(2020-n); int a = d%10; int b = d%12; cout<<tian[a]<<di[b]<<endl; } return 0; }
让我写了60行的代码情何以堪
liuzhendong 2024-01-26 14:03:56 |
#include<iostream> using namespace std; string tian[10] = {"geng","xin","ren","gui","jia","yi","bing","ding","wu","ji"}; string di[12] = {"zi","chou","yin","mao","chen","si","wu","wei","shen","you","xu","hai"} ; int main() { int n; while(cin>>n) if(n>0) { //2020年是庚子年 int d = n>2020?(n-2020):(2020-n); int a = d%10; int b = d%12; cout<<tian[a]<<di[b]<<endl; } return 0; }
点我有惊喜!你懂得!浏览:1274 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1092 |
C语言训练-阶乘和数* (C语言代码)-------- 呆板写法浏览:1397 |
wu-淘淘的名单 (C++代码)浏览:1532 |
WU-拆分位数 (C++代码)浏览:819 |
【计算直线的交点数】 (C语言代码)浏览:1501 |
【亲和数】 (C语言代码)浏览:628 |
局部变量作函数返回值的问题浏览:1029 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:820 |
C语言程序设计教程(第三版)课后习题5.4 (C语言代码)浏览:501 |