zoukankan      html  css  js  c++  java
  • 湖南大学第十四届ACM程序设计新生杯(重现赛)G a+b+c+d=? (16进制与LL范围)

    链接:https://ac.nowcoder.com/acm/contest/338/G
    来源:牛客网

    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 32768K,其他语言65536K
    64bit IO Format: %lld

    题目描述

    This is a very simple problem! Your only job is to calculate a + b + c + d!

    输入描述:

    There are several cases.

    In the first line, there is a single integer T.(T <= 200)

    In the next T lines, each line contains four integers a, b, c and d(-2^61 <= a,b,c,d <=2^61)

    输出描述:

    output T lines.

    Each line output one integer represent the answer of a + b + c + d
    示例1

    输入

    1
    1 2 3 4

    输出

    10

    为什么总有些水题是如此的清奇呢。。QAQ

    1、16进制以0x开头,后面跟数字0~9或字母A~F(小写也可以)。如:0x2D(16进制数2D)

    8进制以0开头,后面跟数字0~7。如:045(8进制数45)

     如果使用printf函数输出时,可以通过格式数明符来控制输出格式。

    int x=23;

    printf("%x", x);  // 以16进制格式输出,输出17
    printf("%o", x);  // 以8进制格式输出,输出27

    2、long long的范围是 -2^63 - 2^63-1

    所以根据题设范围,如果四个数都是2^61,那么相加会溢出!需特判。

    2^63-1表示为16进制为0x7fffffffffffffff

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <stack>
    #include <map>
    #include <set>
    typedef long long ll;
    const int mod=1000000007;
    const int inf=1000000000;
    const ll maxn=0x2000000000000000;
    const ll maxm=0x7fffffffffffffff;
    
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            ll a,b,c,d;
            scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
            if(a==maxn&&b==maxn&&c==maxn&&d==maxn)
                printf("%lld8
    ",maxm/10);
            else
                printf("%lld
    ",a+b+c+d);
        }
        return 0;
    }
    View Code
  • 相关阅读:
    logback配置和使用
    安装多个jdk导致eclipse打不开问题
    Spring事务管理
    使用JavaConfig配置SpringMVC
    Spring pom.xml配置
    Maven私服搭建(Nexus Repository Manager 3)
    Maven多环境配置
    Maven多模块构建实例
    Maven依赖机制
    Maven安装与配置
  • 原文地址:https://www.cnblogs.com/acboyty/p/10279854.html
Copyright © 2011-2022 走看看