nbut 1012 ABS

之前看到,就想,long long 然后取绝对值,当然是错了,-2^63取整后会溢出。int64的范围是-2^63~2^63-1:

 -9223372036854775808 ~  9223372036854775807 

还有一点就是vc6.0还支持__int64.

解决溢出的方法是分段输出。

囧啊,贡献了那么多的wa,ole,pe

字符串水过,之前还没想到,惯性思维啊...>_<

#include<cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
__int64 ABS(__int64 n)
{
	if(n>=0) return n;
	else return -n;
}
int main()
{
	__int64 n,h,l;
	while(~scanf("%I64d",&n))
	{
		h=n/1000000000;
		l=n%1000000000;
		h=ABS(h);
		l=ABS(l);
		if(h)
		printf("%I64d",h);
		if(h)
		printf("%09I64d\n",l);
		else printf("%I64d\n",l);
	}
	return 0;
}


#include <string.h>
#include <stdio.h>
int main()
{
	char a[100];
	while(~scanf("%s",a))
	{
		if(a[0]=='-') 
		printf("%s\n",a+1);
		else printf("%s\n",a);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值