題目來源html
Given three integers A, B and C in [−], you are supposed to tell whether A+B>C.ios
The first line of the input gives the positive number of test cases, T (≤). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.spa
For each test case, output in one line Case #X: true
if A+B>C, or Case #X: false
otherwise, where X is the case number (starting from 1).code
3 1 2 3 2 3 4 9223372036854775807 -9223372036854775808 0
Case #1: false Case #2: true Case #3: false
給定三個數A B C,A + B > C爲true,不然爲falsehtm
要考慮溢出的問題,我這裏用 long double 接收輸入blog
A B C同除1000,而後直接做比較three
#include <iostream> using namespace std; int main() { long double A, B, C; int N; cin >> N; for (int i = 1; i <= N; ++i) { cin >> A >> B >> C; A /= 1000; B /= 1000; C /= 1000; cout << "Case #" << i << ": "; if (A + B > C) { cout << "true" << endl; } else { cout << "false" << endl; } } return 0; }