Tyvj P1401 神牛做减法
背景 Background
董宇涛,董神牛刚坐下,铃响了,数学课开始了......
描述 Description
这节课的科目是做减法,在小学时代,董神牛曾经因为数学课符号弄错,而被罚站。董神牛一朝被蛇咬,十年怕井绳。于是,请你,解决这个难题。
输入格式 Input Format
输入:两个整数a,b(-2^63<=a,b<2^63)
输出格式 Output Format
输出:一个整数,表示两数的差(从个位开始,每隔三位加一个","号)。
样例输入 Sample Input
7777777 –29
样例输出 Sample Output
7,777,806
注释 Hint
DYT提醒您:小心负数!!!
program p1401; var a,b:int64; p,q,s:qword; x,y,t:boolean; rs,r:ansistring; l,i,k:longint; begin read (a,b); x := true; y := true; if a < 0 then begin x := false; p:=abs(a);end else p:=a; if b < 0 then begin y := false; q:=abs(b);end else q:=b; if (x and not(y)) then s := p + q; t := true; if (not(x)and not(y)) then begin if p > q then begin s:=p-q; t:=false; end; if p < q then s := q - p; end; if (x and y) then begin if p > q then s := p - q; if p < q then begin s := q - p;t:=false;end; end; if (not(x)and y) then begin t:=false; s:=p+q; end; str (s,rs); l := length(rs); k := 0; r:=''; if not(t)then write ('-'); for i := l downto 1 do begin if k = 3 then begin r:=r+',';k := 0; end; r:=r+rs[i]; inc(k); end; l := length(r); for i := l downto 1 do write (r[i]); end.