ZOJ 3594 Sexagenary Cycle

题意:天干地支。

        天干: Jia, Yi, Bing, Ding, Wu, Ji, Geng, Xin, Ren and Gui

        地支: Zi, Chou, Yin, Mao, Chen, Si, Wu, Wei, Shen, You, Xu and Hai

        每一轮是60次,不要误认为120次。。。(常识),这道题是经典的水题,很水但是还是被坑了很久大概一下午加一晚上。。。。。搞不懂自己什么水平

说下这道题目的坑把,首先是输出地支的时候是小写。。。其次还有AD和BC之分刚开始没有看见要求BC,最后是定义数组后当取余为0时候应该换到最后一个所以str[(t+9)%12]刚开始的时候把天干也当成12个了 害我找了很久

思路:刚开始看了维基百科里的解法,这也是第一次看英文会的解法,求AD,若n>=4则,n=(n-3)%60,若n=1-3,则代表58th,59th,60th。求BC,n=60-(n+2)%60.

         第二种方法简单,根据1911推导下就ok了,至于BC就是倒着来,和AD刚好相反

 

       

View Code
#include<stdio.h>
int main()
{
    char str1[11][10]={"Jia","Yi","Bing","Ding","Wu","Ji","Geng","Xin","Ren","Gui"};
    char str2[13][10]={"zi","chou","yin","mao","chen","si","wu","wei","shen","you","xu","hai"};
    long n,t1,t2;
    scanf("%ld",&n);
    while(n--)
    {
        int x;
        scanf("%ld",&x);
        if(x==1) printf("Xinyou\n");
        else if(x==2) printf("Renxu\n");
        else if(x==3) printf("Guihai\n");
        else if(x>=4)
        {
            x-=3;
            x=x%60; 
            t1=x%10;
            t2=x%12;
            printf("%s%s\n",str1[(t1+9)%10],str2[(t2+11)%12]);
        }
        else
        {
            x*=-1;
            x+=2;
            x=60-x%60;
            t1=x%10;
            t2=x%12;
            printf("%s%s\n",str1[(t1+9)%10],str2[(t2+11)%12]);
        }
    }
    return 0;
}
View Code
#include <stdio.h>
int main(int argc, char *argv[])
{
    int T,n;
    int t1,t2;
    char str1[15][10]={"Xin","Ren","Gui","Jia","Yi","Bing","Ding","Wu","Ji","Geng"};
    char str2[15][10]={"you","xu","hai","zi","chou","yin","mao","chen","si","wu","wei","shen"};
    char str3[11][10]={"Geng","Ji","Wu","Ding","Bing","Yi","Jia","Gui","Ren","Xin"};
    char str4[15][10]={"shen","wei","wu","si","chen","mao","yin","chou","zi","hai","xu","you"};
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        if(n>0)
        {
           n%=60;
           t1=n%10;
           t2=n%12;
           printf("%s%s\n",str1[(t1+9)%10],str2[(t2+11)%12]);
        }
        else
        {
            n*=-1;
            n%60;
            t1=n%10;
            t2=n%12;
            printf("%s%s\n",str3[(t1+9)%10],str4[(t2+11)%12]);
        }
    }
    return 0;
}

 

posted @ 2012-04-18 10:15  calmound  阅读(388)  评论(0编辑  收藏  举报