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;
    }
  • 相关阅读:
    Elasticsearch5.3 学习(一):安装、Yii2.0 下载es扩展
    lnmp 环境require(): open_basedir restriction in effect 错误
    Ueditor编辑器图片上传到万象优图
    Linux curl 模拟form表单提交信息和文件
    CP936 转换成 UTF-8
    wamp 两个不同的php.ini
    PHP浮点数运算精度造成的,订单金额支付经常少1分的问题
    进制相关:存储与转换
    Python的数据类型
    pycharm+PyQt5 开发配置
  • 原文地址:https://www.cnblogs.com/littlepage/p/11280183.html
Copyright © 2011-2022 走看看