zoj3594 Sexagenary Cycle

本文深入探讨了中国传统的干支纪年系统,通过解析六十甲子的构成及其与公元纪年的转换算法,提供了一种计算任意西元年份对应干支纪年的有效方法。文章详细介绍了天干地支的概念,以及它们如何组合成六十个不同的干支纪年,并通过具体的代码示例展示了算法的实现过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Sexagenary Cycle

Time Limit: 2 Seconds      Memory Limit: 65536 KB

The Chinese sexagenary cycle, also known as the stems-and-branches, is a cycle of sixty terms used for recording days or years. Each term in the sexagenary cycle consists of two Chinese characters, the first representing a term from a cycle of ten known as the heavenly stems and the second from a cycle of twelve known as the earthly branches. The first term (Jiazi) combines the first heavenly stem (Jia) with the first earthly branch (Zi). The second (Yichou) combines the second stem with the second branch. This continues, generating a total of 60 different terms (the least common multiple of ten and twelve), after which the cycle repeats itself.

The ten heavenly stems are Jia, Yi, Bing, Ding, Wu, Ji, Geng, Xin, Ren and Gui. And the twelve earthly branches are Zi, Chou, Yin, Mao, Chen, Si, Wu, Wei, Shen, You, Xu and Hai. E.g. Xinhai Revolution occurred in 1911, the year of the Xinhai stem-branch in the sexagenary cycle. And this year, namely 2012, is the year of Renchen. Given a year in western year, could you find out which year it is in cyclic year?

Actually, the cyclic year normally changes on the Chinese Lunar New Year, but you can ignore this in this problem.

Input

There are multiple test cases. The first line of input is an integer T ≈ 1000 indicating the number of test cases.

Each test case contains a positive integer or a negative integer. A positive integer n indicates n AD (Anno Domini), while a negative integer n indicates -n BC (Before Christ). The absolute values of all integers are strictly less than 10000.

Output

For each test case, output a string -- the corresponding cyclic year.

Sample Input
2
1911
2012
Sample Output
Xinhai
Renchen

分析:-1 的 后面是 1 ;还有就是 后一个是 小写(Xinhai);
View Code
 1 #include<iostream>
2 #include<cstring>
3 #include<string>
4 using namespace std;
5
6 string a[10],b[12];
7
8 int main()
9 {
10 a[0]="Jia";a[1]="Yi";a[2]="Bing";a[3]="Ding";
11 a[4]="Wu";a[5]="Ji";a[6]="Geng";a[7]="Xin";a[8]="Ren";a[9]="Gui";
12 b[0]="zi";b[1]="chou";b[2]="yin";b[3]="mao";b[4]="chen";b[5]="si";
13 b[6]="wu";b[7]="wei";b[8]="shen";b[9]="you";b[10]="xu";b[11]="hai";
14 int i,j,n,test;
15 cin>>test;
16 while(test--)
17 {
18 cin>>n;
19 if(n>0)
20 {
21 n=n+3600;
22 n=n-1911;
23 n=n%60;
24 i=(7+n)%10;
25 j=(11+n)%12;
26 cout<<a[i]<<b[j]<<endl;
27 }
28 else if(n<0)
29 {
30 n=n+36001;
31 n=n-1911;
32 n=n%60;
33 i=(7+n)%10;
34 j=(11+n)%12;
35 cout<<a[i]<<b[j]<<endl;
36 }
37
38 }
39 }

转载于:https://www.cnblogs.com/zhourongqing/archive/2012/04/09/2438332.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值