zoj3594 Sexagenary Cycle
2012-04-09 00:33
218 查看
Sexagenary CycleTime 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.
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.
View Code
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
#include<iostream> #include<cstring> #include<string> using namespace std; string a[10],b[12]; int main() { a[0]="Jia";a[1]="Yi";a[2]="Bing";a[3]="Ding"; a[4]="Wu";a[5]="Ji";a[6]="Geng";a[7]="Xin";a[8]="Ren";a[9]="Gui"; b[0]="zi";b[1]="chou";b[2]="yin";b[3]="mao";b[4]="chen";b[5]="si"; b[6]="wu";b[7]="wei";b[8]="shen";b[9]="you";b[10]="xu";b[11]="hai"; int i,j,n,test; cin>>test; while(test--) { cin>>n; if(n>0) { n=n+3600; n=n-1911; n=n%60; i=(7+n)%10; j=(11+n)%12; cout<<a[i]<<b[j]<<endl; } else if(n<0) { n=n+36001; n=n-1911; n=n%60; i=(7+n)%10; j=(11+n)%12; cout<<a[i]<<b[j]<<endl; } } }
相关文章推荐
- ZOJ3594 Sexagenary Cycle
- ZOJ 3594 Sexagenary Cycle
- ZOJ 3594 Sexagenary Cycle
- ZOJ - 3594 Sexagenary Cycle(公元没有0年)
- Sexagenary Cycle(干支纪年)
- zoj 3594 Sexagenary Cycle(模拟)
- ZOJ-3594 Sexagenary Cycle【简单模拟】
- Sexagenary Cycle(天干地支法表示农历年份)
- LeetCode-Linked List Cycle
- [leetcode] Linked List Cycle II
- Linked List Cycle II
- [Leetcode][JAVA] Linked List Cycle I && II
- LeetCode-Linked List Cycle II -有环链表-推理
- Android Lifecycle
- LeetCode:Linked List Cycle
- LeetCode——Linked List Cycle
- leetcode linked-list-cycle
- HDU1700 Points on Cycle (最大内接三角形)
- leetcode Linked List Cycle II
- [leetcode 141] Linked List Cycle