题目大意
给定一个公元纪年的年份 \(n\),请输出这一年的天干地支年份。
解题思路
将天干和地支分别存到 \(a,b\) 数组里;
因为天干是 \(10\) 年一轮回,地支是 \(12\) 年一轮回,所以 \(n\bmod10\) 等于几,天干就是第几个;\(n\bmod 12\) 等于几,地支就是第几个。
所以只需要输出 \(a_{n \bmod 10}\) 和 \(b_{n \bmod 12}\) 即可。
代码
#include<bits/stdc++.h>
using namespace std;
int n;
string a[15]= {"geng","xin","ren","gui","jia","yi","bing","ding","wu","ji"};
string b[15]= {"shen","you","xu","hai","zi","chou","yin","mao","chen","si","wu","wei"};
int main() {
cin>>n;
cout<<a[n%10]<<b[n%12];
return 0;
}
标签:12,天干地支,天干,地支,蓝桥,2020,bmod
From: https://www.cnblogs.com/zzyblog0619/p/17153717.html