首先打表.
1.对于公元后的年份,位置为(year-3)%60若结果为负数则加60.
2.对于公元前的年份,位置为(year-2)%60若结果为负数则加60.
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <string>
using namespace std;
const int maxn=100;
char tb[maxn][20];
char hs[12][15]={"jia", "yi", "bing", "ding", "wu", "ji", "geng", "xin", "ren","gui"};
char eb[14][15]={"zi", "chou", "yin", "mao", "chen", "si", "wu", "wei", "shen", "you", "xu","hai"};
void init(){
int j=0,k=0;
for(int i=1;i<=60;++i,j=(j+1)%10,k=(k+1)%12){
string s=hs[j];
s+=eb[k];
s[0]-=32;
strcpy(tb[i],s.c_str());
}
}
int main(){
int t;
init();
scanf("%d",&t);
while(t--){
int y;
scanf("%d",&y);
int r;
if(y>0){
r=(y-3)%60;
}else{
r=(y-2)%60;
}
if(r<=0)r+=60;
printf("%s\n",tb[r]);
}
return 0;
}