解题思路:通过题意计算出第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.0分

3 人评分

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 10 条评论

橘子芒 10月前 回复TA
牛逼
liuzhendong 11月前 回复TA
@liuzhendong 我是把庚子分别放到数组的第一个,然后对10和对12的余数作为偏移量,因为庚子是第一个所以这个就是下标
liuzhendong 11月前 回复TA
#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 11月前 回复TA
@叮叮咚咚嗒 #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;  }
liuzhendong 11月前 回复TA
@王曹禹 #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;  }
叮叮咚咚嗒 2年前 回复TA
@叮叮咚咚嗒 好的,谢谢
笔盖大失 2年前 回复TA
@叮叮咚咚嗒 天干初始在下标为6的地方即 庚 同理,初始地支在下标为8的地方即  申
叮叮咚咚嗒 2年前 回复TA
大佬们,请问怎么理解tstar=6和dstar=8呀?
王曹禹 2年前 回复TA
让我写了60行的代码情何以堪
王曹禹 2年前 回复TA
大师你也太牛了