• Programming Ability Test学习 1037. 在霍格沃茨找零钱(20)


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

    时间限制
    400 ms
    内存限制
    65536 kB
    代码长度限制
    8000 B
    判题程序
    Standard
    作者
    CHEN, Yue

    如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(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
    
    输入样例2:
    14.1.28 10.16.27
    
    输出样例2:
    -3.2.1
    

    提交代码

    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<cstdlib>
    #include<cstring>
    #include<string>
    #include<algorithm> 
    #define MAXSIZE 100005
    #define Max 30
    using namespace std;
    
    typedef struct community
    {
        int Galleon;
        int Sickle;
        int Knut;
    }CM;
    int main()
    {
        CM a[3];
        int cp=0;
        scanf("%d.%d.%d",&a[0].Galleon,&a[0].Sickle,&a[0].Knut);
        getchar();
        scanf("%d.%d.%d",&a[1].Galleon,&a[1].Sickle,&a[1].Knut);
        
        a[0].Knut+=(a[0].Galleon*17+a[0].Sickle)*29;
        a[1].Knut+=(a[1].Galleon*17+a[1].Sickle)*29;
        //cout<<a[0].Knut<<" "<<a[1].Knut<<endl;
        a[2].Knut=a[1].Knut-a[0].Knut;
        if(a[2].Knut<0){
            cp=1;
            a[2].Knut*=(-1);
        }
        //cout<<a[2].Knut<<endl;
        a[2].Sickle=a[2].Knut/29;
        a[2].Knut=a[2].Knut%29;
        a[2].Galleon=a[2].Sickle/17;
        a[2].Sickle=a[2].Sickle%17;
        
        if(cp==1){
            cout<<-a[2].Galleon<<"."<<a[2].Sickle<<"."<<a[2].Knut<<endl;
        }
        else cout<<a[2].Galleon<<"."<<a[2].Sickle<<"."<<a[2].Knut<<endl;
        
        return 0;
    }
    View Code
  • 相关阅读:
    博客园第一篇随笔css3动画(奔跑的小杨)
    Python输出菱形
    Android开发经验总结
    Android中Activity共享变量的另一方法:Application context
    system()与execv()函数使用详解
    Sublime Text2 编译和运行C/C++程序(windows)
    Android View.post(Runnable )
    Android图像处理之Bitmap类
    android中dip、dp、px、sp和屏幕密度
    System.setProperty and System.getProperty
  • 原文地址:https://www.cnblogs.com/a842297171/p/4778273.html
Copyright © 2020-2023  润新知