码迷,mamicode.com
首页 > 编程语言 > 详细

PAT 甲级 1065.A+B and C C++/Java

时间:2020-02-05 21:51:51      阅读:72      评论:0      收藏:0      [点我收藏+]

标签:java   个数   one   name   for   分析   bin   溢出   div   

题目来源

Given three integers A, B and C in [−], you are supposed to tell whether A+B>C.

Input Specification:

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.

Output Specification:

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).

Sample Input:

3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0
 

Sample Output:

Case #1: false
Case #2: true
Case #3: false

题目大意:

给定三个数A B C,A + B > C为true,否则为false

分析:

要考虑溢出的问题,我这里用 long double 接收输入

A B C同除1000,然后直接作比较

C++实现:

#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;
}

 

 

 

Java实现:

 

 

PAT 甲级 1065.A+B and C C++/Java

标签:java   个数   one   name   for   分析   bin   溢出   div   

原文地址:https://www.cnblogs.com/47Pineapple/p/12266778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!