• PAT乙级1037


    1037 在霍格沃茨找零钱 (20 分)
     

    如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易。”现在,给定哈利应付的价钱 P 和他实付的钱 A,你的任务是写一个程序来计算他应该被找的零钱。

    输入格式:

    输入在 1 行中分别给出 P 和 A,格式为 Galleon.Sickle.Knut,其间用 1 个空格分隔。这里 Galleon 是 [0, 107​​] 区间内的整数,Sickle 是 [0, 17) 区间内的整数,Knut 是 [0, 29) 区间内的整数。

    输出格式:

    在一行中用与输入同样的格式输出哈利应该被找的零钱。如果他没带够钱,那么输出的应该是负数。

    输入样例 1:

    10.16.27 14.1.28
    

    输出样例 1:

    3.2.1
    
     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<algorithm>
     5 #include<cmath>
     6 #include<vector>
     7 #include<queue>
     8 #include<bits/stdc++.h>
     9 using namespace std;
    10 bool f;
    11 struct node
    12 {
    13     int a,b,c;
    14 }e[3];
    15 bool cmp(node x,node y)
    16 {
    17     if(x.a!=y.a)
    18         return x.a<y.a;
    19     else if(x.b!=y.b)
    20         return x.b<y.b;
    21     else if(x.c!=y.c)
    22         return x.c<=y.c;
    23 }
    24 int main()
    25 {
    26     int a=0,b=0,c=0;
    27     scanf("%d.%d.%d %d.%d.%d",&e[0].a,&e[0].b,&e[0].c,&e[1].a,&e[1].b,&e[1].c);
    28     e[2].a=e[1].a;
    29     sort(e,e+2,cmp);
    30     //cout<<e[0].a<<e[1].a;
    31     if(e[1].a==e[2].a)f=1;
    32     if(e[1].c<e[0].c)
    33         {
    34             c=e[1].c+29-e[0].c;
    35             e[1].b-=1;
    36         }
    37     else
    38         c=e[1].c-e[0].c;
    39     if(e[1].b<e[0].b)
    40     {
    41         b=e[1].b+17-e[0].b;
    42         e[1].a-=1;
    43     }
    44     else
    45         b=e[1].b-e[0].b;
    46     a=e[1].a-e[0].a;
    47     if(f==0)
    48         cout<<"-";
    49         printf("%d.%d.%d",a,b,c);
    50     return 0;
    51 }

    测试点2一开始没过,原因是把cmp函数写错了。

  • 相关阅读:
    link和@import区别
    常用的正则表达式
    virtual dom
    git常用命令
    系统管理与进程命令
    Shell 命令
    软件安装命令
    vim 详解
    网络命令
    帮助与用户管理命令
  • 原文地址:https://www.cnblogs.com/zuiaimiusi/p/10878397.html
Copyright © 2020-2023  润新知