zoukankan      html  css  js  c++  java
  • PAT B1037 在霍格沃兹找零钱

    AC代码

    #include <cstdio>
    #include <algorithm>
    
    using namespace std;
    
    char flag = 0; //判断付钱数是否大于价格
    struct Money {
        int Galleon, Sickle, Knut;
    } price, pay, temp, sub;
    
    void init() {
        price.Galleon = pay.Galleon = temp.Galleon = 0;
        price.Sickle = pay.Sickle = temp.Sickle = 0;
        price.Knut = pay.Knut = temp.Knut = 0;
    }
    void Sub(Money a, Money b) {  //a为付钱, b为价格
        if(a.Knut >= b.Knut) {
            temp.Knut = a.Knut - b.Knut;
        } else if(a.Knut < b.Knut) {
            a.Sickle -= 1;
            temp.Knut = a.Knut + 29 - b.Knut;
        }
        //printf("a.Sickle = %d c.Knut = %d
    ", a.Sickle, c.Knut);
        //printf("before_____a.Galleon = %d
    ", a.Galleon);
        if(a.Sickle >= b.Sickle) {
            temp.Sickle = a.Sickle - b.Sickle;
        } else if(a.Sickle < b.Sickle) {
            a.Galleon -= 1;
            temp.Sickle = a.Sickle + 17 - b.Sickle;
        }
        //printf("after_____a.Galleon = %d
    ", a.Galleon);
        temp.Galleon = a.Galleon - b.Galleon;
    }
    
    int main() {
        #ifdef ONLINE_JUDGE
        #else
            freopen("1.txt", "r", stdin);
        #endif // ONLINE_JUDGE
        init();
        scanf("%d.%d.%d %d.%d.%d", &price.Galleon, &price.Sickle, &price.Knut, &pay.Galleon, &pay.Sickle, &pay.Knut);
    //    printf("price:%d.%d.%d  pay:%d.%d.%d
    ", price.Galleon, price.Sickle, price.Knut, pay.Galleon, pay.Sickle, pay.Knut);
        if(pay.Galleon < price.Galleon) {
            swap(price, pay);
            flag = 1;
        }
    //    printf("flag:%c
    ", flag);
    //    printf("price:%d.%d.%d  pay:%d.%d.%d
    ", price.Galleon, price.Sickle, price.Knut, pay.Galleon, pay.Sickle, pay.Knut);
        Sub(pay, price);
        if(flag == 1) printf("-");
        printf("%d.%d.%d", temp.Galleon, temp.Sickle, temp.Knut);
        return 0;
    }
    
  • 相关阅读:
    Ruby(1):入门
    html 制作静态页面新知识
    mysql 可视化界面操作指令
    html 基础
    Eclipse导入Java工程导入错误
    shell 25个常用命令
    java JDBC
    java 8新特性 instant
    git
    spring mvc 注解详解
  • 原文地址:https://www.cnblogs.com/isChenJY/p/11299053.html
Copyright © 2011-2022 走看看