#include<iostream>
#include<stdio.h>
using namespace std;
int c_G, c_S, c_K;
//一个做差函数,此函数总是大的减去小的
int calcu(int a_G, int a_S, int a_K, int b_G, int b_S, int b_K)
{
if (b_K >= a_K)
{
c_K = b_K - a_K;
}
else {
c_K = 29 - a_K + b_K;
b_S = b_S - 1;
}
if (b_S >= a_S)
{
c_S = b_S - a_S;
}
else
{
c_S = 17 - a_S + b_S;
b_G = b_G - 1;
}
c_G = b_G - a_G;
//cout << c_G << "." << c_S << "." << c_K << endl;
return c_G, c_S, c_K;
}
void test()
{
int a_G, a_S, a_K;
int b_G, b_S, b_K;
scanf("%d.%d.%d %d.%d.%d", &a_G, &a_S, &a_K, &b_G, &b_S, &b_K);
//由于要使用我们自定义的做差函数,所以要进行输入数的大小判定
if (b_G * 29 * 17 + b_S * 29 + b_K > a_G * 29 * 17 + a_S * 29 + a_K)
{
c_G, c_S, c_K = calcu(a_G, a_S, a_K, b_G, b_S, b_K);
cout << c_G << "." << c_S << "." << c_K << endl;
}
else if (b_G * 29 * 17 + b_S * 29 + b_K < a_G * 29 * 17 + a_S * 29 + a_K)
{
c_G, c_S, c_K = calcu( b_G, b_S, b_K, a_G, a_S, a_K);
cout << "-" << c_G << "." << c_S << "." << c_K << endl;
}
else if (b_G * 29 * 17 + b_S * 29 + b_K == a_G * 29 * 17 + a_S * 29 + a_K)
{
cout << "0.0.0" << endl;
}
}
int main()
{
test();
return 0;
}
【PAT-B1037】 在霍格沃茨找零钱 (20 分)(c++)
最新推荐文章于 2024-08-26 17:31:44 发布