Sexagenary Cycle(天干地支法表示农历年份)

Sexagenary Cycle

Time Limit: 2 Seconds      Memory Limit: 65536 KB

题目链接:zoj 4669

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

References

  • http://en.wikipedia.org/wiki/Sexagenary_cycle
  • 题目大意:
  • 给出一个整数n,代表有n组数据,每组数据都有一个整数,代表年份,年份有负有正,负数代表的是公元前,正数代表的是公元后,求用天干地支法表示出每个年份。

    与天干地支相关的资料链接:http://www.pep.com.cn/gzls/xs/lszs/201101/t20110110_1014103.htm

    代码:

 1 #include<iostream>
 2 #include<string.h>
 3 using namespace std;
 4 int main()
 5 {
 6     char f1[][82]={"Xin","Geng","Ji","Wu","Ding","Bing","Yi","Jia","Gui","Ren"};
 7     char g1[][82]={"you","shen","wei","wu","si","chen","mao","yin","chou","zi","hai","xu"};
 8     char f2[][82]={"Geng","Xin","Ren","Gui","Jia","Yi","Bing","Ding","Wu","Ji","Geng"};
 9      char g2[][82]={"shen","you","xu","hai","zi","chou","yin","mao","chen","si","wu","wei","shen"};
10         int zong;
11         cin>>zong;
12         while(zong--)
13         {
14             int year;
15             cin>>year;
16             if(year>0)
17             {
18                 int yu=year%10;
19             cout<<f2[yu];
20             yu=year%12;
21             cout<<g2[yu];
22             cout<<endl;
23             }
24             else
25             {
26                 int yu=(-1*year)%10;
27                 cout<<f1[yu];
28                 yu=(-1*year)%12;
29                 cout<<g1[yu];
30                 cout<<endl;
31             }
32         }
33     return 0;
34 }
View Code
原文地址:https://www.cnblogs.com/kuangdaoyizhimei/p/3279203.html