zoukankan      html  css  js  c++  java
  • PAT Advanced 1065 A+B and C (64bit) (20 分)(关于g++和clang++修改后能使用)

    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


    这个上面有2个Case是不能过的,在g++,但是在clang++可以过。
    #include <iostream>
    using namespace std;
    int main(){
        /**
        依据算法笔记,以及其他人的博客,可知
        可以进行溢出判断
        1.即两个正数和为负数,溢出,比结果大
        2.两个负数和为正数,溢出,比结果肯定小
        3.一正一负直接比较
        long long长度[-2**63,2**63)
        */
        int T;long long a,b,c;
        cin>>T;bool flag;//flag为true是true,false为false
        for(int i=0;i<T;i++){
            cin>>a>>b>>c;
            if(a>0&&b>0&&(a+b)<0) flag=true;
            else if(a<0&&b<0&&(a+b)>=0) flag=false;
            else{
                if(a+b>c) flag=true;
                else flag=false;
            }
            if(flag) cout<<"Case #"<<(i+1)<<": true"<<endl;
            else cout<<"Case #"<<(i+1)<<": false"<<endl;
        }
        system("pause");
        return 0;
    }

    要想在g++过这个Case 可以使用用res存储的方式。至今不知道为啥不能直接比较,在g++上
    #include <iostream>
    using namespace std;
    int main(){
        /**
        依据算法笔记,以及其他人的博客,可知
        可以进行溢出判断
        1.即两个正数和为负数,溢出,比结果大
        2.两个负数和为正数,溢出,比结果肯定小
        3.一正一负直接比较
        long long长度[-2**63,2**63)
        */
        int T;long long a,b,c,res;
        cin>>T;bool flag;//flag为true是true,false为false
        for(int i=0;i<T;i++){
            cin>>a>>b>>c;
            res=a+b;
            if(a>0&&b>0&&res<0) flag=true;
            else if(a<0&&b<0&&res>=0) flag=false;
            else{
                if(res>c) flag=true;
                else flag=false;
            }
            if(flag) cout<<"Case #"<<(i+1)<<": true"<<endl;
            else cout<<"Case #"<<(i+1)<<": false"<<endl;
        }
        system("pause");
        return 0;
    }
  • 相关阅读:
    Linux实战教学笔记16:磁盘原理
    Linux实战教学笔记15:用户管理初级(下)
    Linux实战教学笔记14:用户管理初级(上)
    Linux实战教学笔记13:定时任务补充
    Linux实战教学笔记12:linux三剑客之sed命令精讲
    Linux实战教学笔记11:linux定时任务
    Linux实战教学笔记10:正则表达式
    Linux实战教学笔记09:通配符
    Linux实战教学笔记08:Linux 文件的属性(下半部分)
    Linux实战教学笔记08:Linux 文件的属性(上半部分)
  • 原文地址:https://www.cnblogs.com/littlepage/p/11280183.html
Copyright © 2011-2022 走看看