PAT乙级1037(C语言)-在霍格沃茨找零钱(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
输入样例2:
14.1.28 10.16.27
输出样例2:

-3.2.1

#include
int main() {
  int yingfu_G, yingfu_S, yingfu_K, shifu_G, shifu_S, shifu_K,zhao_G,zhao_S,zhao_K;
  scanf("%d.%d.%d %d.%d.%d", &yingfu_G, &yingfu_S, &yingfu_K, &shifu_G, &shifu_S, &shifu_K);
  if (shifu_G * 17 * 29 + shifu_S * 29 + shifu_K >= yingfu_G * 17 * 29 + yingfu_S * 29 + yingfu_K) {
    if (shifu_K >= yingfu_K) zhao_K = shifu_K - yingfu_K;
    else { shifu_S -= 1; zhao_K = shifu_K + 29 - yingfu_K; }
    if (shifu_S >= yingfu_S) zhao_S = shifu_S - yingfu_S;
    else { shifu_G -= 1; zhao_S = shifu_S + 17 - yingfu_S; }
    zhao_G = shifu_G - yingfu_G;
    printf("%d.%d.%d", zhao_G, zhao_S, zhao_K);
  }
  else {
    int temp_K = shifu_K; shifu_K = yingfu_K; yingfu_K = temp_K;
    int temp_S = shifu_S; shifu_S = yingfu_S; yingfu_S = temp_S;
    int temp_G = shifu_G; shifu_G = yingfu_G; yingfu_G = temp_G;
    if (shifu_K >= yingfu_K) zhao_K = shifu_K - yingfu_K;
    else { shifu_S -= 1; zhao_K = shifu_K + 29 - yingfu_K; }
    if (shifu_S >= yingfu_S) zhao_S = shifu_S - yingfu_S;
    else { shifu_G -= 1; zhao_S = shifu_S + 17 - yingfu_S; }
    zhao_G = shifu_G - yingfu_G;
    printf("-%d.%d.%d", zhao_G, zhao_S, zhao_K);
  }
  system("pause");
  return 0;
}


你可能感兴趣的:(PAT乙级)