Fork me on github

湖南大学第十四届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\n",maxm/10);
        else
            printf("%lld\n",a+b+c+d);
    }
    return 0;
}
View Code

 

posted @ 2019-01-16 22:34  acboyty  阅读(295)  评论(0编辑  收藏  举报