八十分,莫名其妙

八十分求助
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<bitset>
#include<stack>
#define ll long long
#define ull unsigned long long
using namespace std;
ll read(){
    ll num=0,bj=1;
    char x=getchar();
    while(x<'0'||x>'9') {
        if(x=='-')bj=-1;
        x=getchar();
    }
    while(x>='0'&&x<='9') {
        num=num*10+x-'0';
        x=getchar();
    }
    return num*bj;
}
int aa=1,bb=1;
ll a,b;
ull A,B,ans;
int main(){
//    freopen("t1.in","r",stdin);
//    freopen("t1.out","w",stdlib);
    a=read();
    b=read();
    if(a<0){
        aa=-1;
        A=-a;
    }
    else A=a;
    if(b<0){
        bb=-1;
        B=-b;
    }
    else B=b;
    if(aa!=bb){
        cout<<a+b<<endl;
        return 0;
    }
//    cout<<A<<" "<<a<<" "<<aa<<" "<<B<<" "<<" "<<b<<" "<<bb<<endl;
    if(max(A,B)!=max(a,b))swap(aa,bb);
    ans=A*aa+B*bb;
    if(aa==bb){
        if(aa==-1){
            if(ans>9223372036854775808){
                cout<<char(34)<<"hello, %lld"<<char(92)<<"n"<<char(34)<<endl;
                return 0;
            }
            else cout<<"-"<<ans<<endl;
        }
        else{
            if(ans>9223372036854775807){
                cout<<char(34)<<"hello, %lld"<<char(92)<<"n"<<char(34)<<endl;
                return 0;
            }
            else cout<<ans<<endl;
        }
    }
    return 0;
}


全部评论
特判0 0 然后只要算两个数加起来有没有符号反
点赞 回复 分享
发布于 2018-09-27 21:45
其实这题没那么复杂 a,b两个数都在long long里,所以只要计算其中一个数离边界有多远,用另外一个数来做比较就好了
点赞 回复 分享
发布于 2018-09-16 09:30

相关推荐

ZywOo_求职版:谁问你了....
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务