#include<stdio.h>
int main()
{
__int64 a,b,cha,tt;
int c[100]={0};
while(scanf("%I64d%I64d",&a,&b)==2)
{
cha=a-b;
if(cha==0) printf("0\n");
else
{tt=cha;
if(cha<0) { printf("-"); tt=0-cha; } //在这里将负数转换成正数时不能用函数abs,因为函数abs作用域为int型,会照成数据丢失
int i=1,n=1;
while(tt)
{
c[i]=tt%10;
tt/=10;
i++;
n++;
}
for(i=n-1;i>=1;i--)
{
if(i<n-1&&i%3==0) printf(",");
printf("%d",c[i]);
}
printf("\n");
}
}
return 0;
}
这个题不要用int64,要用无符号的,因为2^63-(-2^63)就超过int64的范围了,用无符号的qword(pascal)或 unsign long long int(c++)!
我的ac代码
var a:array[1..2] of qword;s:string;i,l,u,k,q:longint;ch:char;b:array[1..2] of boolean;
begin
readln(s);
u:=pos(' ',s);k:=1;q:=u+1;l:=length(s);
if s[1]='-' then begin b[1]:=true;inc(k); end;
if s[u+1]='-' then begin b[2]:=true;inc(q);end;
val(copy(s,k,u-k),a[1]);
val(copy(s,q,l-q+1),a[2]);
if (b[1]=false)and(b[2]=false) then begin if a[1]>=a[2] then a[1]:=a[1]-a[2] else begin a[1]:=a[2]-a[1];write('-');end;end
else if (b[1]=false)and(b[2]=true) then a[1]:=a[1]+a[2] else
if (b[1]=true)and(b[2]=false) then begin a[1]:=a[2]+a[1];write('-');end
else if (b[1]=true) and (b[2]=true) then begin if a[2]>=a[1] then a[1]:=a[2]-a[1] else begin a[1]:=a[1]-a[2];write('-');end;end;
str(a[1],s);
l:=length(s);
u:=l mod 3;
for i:=1 to l do
begin
write(s[i]);
if i>=u then
if ((i-u) mod 3=0)and(i<>l) then write(',');
end;
end.