PAT考试乙级1037(C语言实现)

#include
#include
int main(){
    int Galleon1,Sickle1,Knut1,sum1=0;
    int Galleon2,Sickle2,Knut2,sum2=0;
    int Galleon3=0,Sickle3=0,Knut3=0;
    int fee;
    scanf("%d.%d.%d",&Galleon1,&Sickle1,&Knut1);
    scanf("%d.%d.%d",&Galleon2,&Sickle2,&Knut2);
    sum1=Galleon1*17*29+Sickle1*29+Knut1;
    sum2=Galleon2*17*29+Sickle2*29+Knut2;
    //printf("%d %d\n",sum1,sum2);
    fee=abs(sum2-sum1);
    while(fee>0){
        if(fee<29){
            Knut3=fee;
            break;
        }else{
            fee=fee-29;
            Sickle3++;
            if(Sickle3>=17){
                Sickle3=Sickle3-17;
                Galleon3++;
            }
        }
    }
    if(sum2-sum1>0)
        printf("%d.%d.%d\n",Galleon3,Sickle3,Knut3);
    else
        printf("%d.%d.%d\n",-Galleon3,Sickle3,Knut3);
    return 0;
}

总结:
注意全部转化为最小单位

你可能感兴趣的:(PAT)