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提醒您:小心负数!!!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 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 . |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步