https://pintia.cn/problem-sets/994805342720868352/problems/994805406352654336
方法一: 用高精度的板子写一下是可以的,不过因为有正负号,故得分类讨论,实属复杂。
方法二: 直接用long double 来计算
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
int t; cin>>t;
for(int i=1;i<=t;i++)
{
long double a,b,c; cin>>a>>b>>c;
if(a+b>c) printf("Case #%d: true\n",i);
else printf("Case #%d: false\n",i);
}
return 0;
}
方法三: 直接用__int128来计算
因为__int128不能直接的读入,故得自己写一个读入的函数,这里直接用p云大佬的代码。
#include <iostream>
using namespace std;
template <typename T>
inline T read()
{
T sum = 0, fl = 1;
int ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-')
fl = -1;
for (; isdigit(ch); ch = getchar())
sum = sum * 10 + ch - '0';
return sum * fl;
}
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; i++)
{
__int128_t a, b, c;
a = read<__int128_t>(), b = read<__int128_t>(), c = read<__int128_t>();
if (a + b > c) cout << "Case #" << i << ": true" << endl;
else cout << "Case #" << i << ": false" << endl;
}
}