之前看到,就想,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;
}