zoukankan      html  css  js  c++  java
  • 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.
    

    嗯……这题的正常做法是高精度,但这题还有个YD的法子……看数据限制(a,b)<|2^63|,我们可以用int64来读入,然后用qword来做加减,前面再附上个符号,分四种情况讨论就行了~

  • 相关阅读:
    myeclipse连接并运行sql文件
    搜集的一些常用的方法
    使用SolrJ代码导入,发布搜索服务
    solr客户端的使用
    Ubuntu搭建solr搜索服务器
    Intersecting Lines(叉积,方程)
    Labyrinth(记忆化BFS)
    Segments(叉积)
    TOYS(叉积)
    Treasures and Vikings(两次搜索)
  • 原文地址:https://www.cnblogs.com/yachen/p/1952886.html
Copyright © 2011-2022 走看看