72 条题解

  • 0
    @ 2021-02-09 09:02:48
  • 0
    @ 2017-05-13 02:45:23

    #include <iostream>
    #include<iomanip>
    //#define Debug

    using namespace std;
    int main()
    {
    long long a, b;
    unsigned long long c,x,y;
    cin >> a >> b;
    if (a < 0)
    {
    x = -a;
    }
    else
    {
    x = a;
    }

    if (b< 0)
    {
    y = -b;
    }
    else
    {
    y = b;
    }
    /*cout << a << " " << b;
    cout << endl;
    cout <<x << " " << y;*/
    if (a == 0 || b == 0) {
    cout << "0";
    system("pause");
    return 0;
    }
    if (a>0 && b<0)
    {
    c = x+y;
    int q = 0;
    while (c >0)//获取三位的个数
    {
    c = c / 1000;
    q++;
    }

    #ifdef Debug
    cout << q << endl;
    #endif
    c = x + y;
    int *d = new int[q];
    for (int t = 0; t < q; t++) //分离
    {
    d[t] = c - ((c / 1000) * 1000);
    c = c / 1000;

    }

    for (int t = (q - 1); t >= 0; t--) //输出
    {
    if (q == 1)
    {
    cout << d[0];
    }
    else
    {
    if (t == 0)
    {
    cout << setw(3) << setfill('0') << d[0];
    }
    else
    {
    if (t == (q - 1))
    {
    cout << d[t] << ",";
    }
    else
    {
    cout << setw(3) << setfill('0') << d[t] << ",";
    }

    }

    }
    }
    delete[]d;

    }
    else if (a<0 && b>0)
    {
    c = x+y;
    cout<<"-";
    int q = 0;
    while (c >0)//获取三位的个数
    {
    c = c / 1000;
    q++;
    }

    #ifdef Debug
    cout << q << endl;
    #endif
    c = x + y;
    int *d = new int[q];
    for (int t = 0; t < q; t++) //分离
    {
    d[t] = c - ((c / 1000) * 1000);
    c = c / 1000;

    }

    for (int t = (q - 1); t >= 0; t--) //输出
    {
    if (q == 1)
    {
    cout << d[0];
    }
    else
    {
    if (t == 0)
    {
    cout << setw(3) << setfill('0') << d[0];
    }
    else
    {
    if (t == (q - 1))
    {
    cout << d[t] << ",";
    }
    else
    {
    cout << setw(3) << setfill('0') << d[t] << ",";
    }

    }

    }
    }
    delete[]d;

    }
    else
    {
    long long c;
    c=(a-b);
    int q = 0;
    if (c >= 0)
    {
    while (c >0)//获取三位的个数
    {
    c = c / 1000;
    q++;
    }

    #ifdef Debug
    cout << q << endl;
    #endif
    c = a - b;
    int *d = new int[q];
    for (int t = 0; t < q; t++) //分离
    {
    d[t] = c - ((c / 1000) * 1000);
    c = c / 1000;

    }

    for (int t = (q - 1); t >= 0; t--) //输出
    {
    if (q == 1)
    {
    cout << d[0];
    }
    else
    {
    if (t == 0)
    {
    cout << setw(3) << setfill('0') << d[0];
    }
    else
    {
    if (t == (q - 1))
    {
    cout << d[t] << ",";
    }
    else
    {
    cout << setw(3) << setfill('0') << d[t] << ",";
    }

    }

    }
    }

    delete[]d;
    }
    else
    {
    long long e = -c;
    #ifdef Debug
    cout << "***" << e << "***" << endl;
    #endif
    while (e >0)//获取三位的个数
    {
    e = e / 1000;
    q++;
    }

    #ifdef Debug
    cout << q << endl;
    #endif
    e = -(a - b);
    int *d = new int[q];
    for (int t = 0; t < q; t++) //分离
    {
    d[t] = e - ((e / 1000) * 1000);
    e = e / 1000;

    }
    cout << "-";

    for (int t = (q - 1); t >= 0; t--) //输出
    {
    if (q == 1)
    {
    cout << d[0];
    }
    else
    {
    if (t == 0)
    {
    cout << setw(3) << setfill('0') << d[0];
    }
    else
    {
    if (t == (q - 1))
    {
    cout << d[t] << ",";
    }
    else
    {
    cout << setw(3) << setfill('0') << d[t] << ",";
    }

    }

    }
    }

    delete[]d;
    }

    }

    system("pause");
    return 0;
    }

  • 0
    @ 2016-02-15 11:25:52

    var a,b:int64;
    s:qword;
    l,i,t:longint;
    x:string;
    begin
    readln(a,b);
    if a>b then s:=a-b
    else s:=b-a;
    if b>a then write('-');
    str(s,x);
    l:=(length(x) div 3)*3;
    if length(x)mod 3=0 then l:=l-3;
    t:=length(x);
    for i:=1 to length(x) do
    begin
    if (l>=t) then begin
    write(',');
    l:=l-3;
    end;
    write(x[i]);
    dec(t);
    end;
    end.

  • 0
    @ 2014-10-28 14:36:22

    评测结果
    编译成功

    测试数据 #0: Accepted, time = 0 ms, mem = 524 KiB, score = 10

    测试数据 #1: Accepted, time = 0 ms, mem = 528 KiB, score = 10

    测试数据 #2: Accepted, time = 0 ms, mem = 528 KiB, score = 10

    测试数据 #3: Accepted, time = 15 ms, mem = 528 KiB, score = 10

    测试数据 #4: Accepted, time = 0 ms, mem = 520 KiB, score = 10

    测试数据 #5: Accepted, time = 0 ms, mem = 524 KiB, score = 10

    测试数据 #6: Accepted, time = 0 ms, mem = 520 KiB, score = 10

    测试数据 #7: Accepted, time = 0 ms, mem = 528 KiB, score = 10

    测试数据 #8: Accepted, time = 0 ms, mem = 520 KiB, score = 10

    测试数据 #9: Accepted, time = 0 ms, mem = 524 KiB, score = 10

    Accepted, time = 15 ms, mem = 528 KiB, score = 100

  • 0
    @ 2013-10-20 19:11:29

    高精度打了100行 已疯

  • 0
    @ 2012-11-27 21:49:23

    ├ 测试数据 01:答案正确... (14ms, 676KB)

    ├ 测试数据 02:答案正确... (0ms, 676KB)

    ├ 测试数据 03:答案正确... (15ms, 676KB)

    ├ 测试数据 04:答案正确... (13ms, 676KB)

    ├ 测试数据 05:答案正确... (0ms, 676KB)

    AC 35 题

  • 0
    @ 2012-08-06 23:21:29

    #01: Accepted (442ms, 580KB)

    #02: Accepted (453ms, 580KB)

    #03: Accepted (250ms, 580KB)

    #04: Accepted (293ms, 580KB)

    #05: Accepted (203ms, 580KB)

    Accepted / 100 / 1644ms / 580KB

    高精度!水

  • 0
    @ 2009-11-08 19:25:12

    为什么要高精度呢??INT64 ,QWORD, STRING直接暴力解决

  • 0
    @ 2009-11-07 15:08:43

    无聊~~~~~~~~~~~~~

    不是高精度~~~~~~~~~~~~

    直接加减~~~~~~~~~~~~~~~~

    在加符号~~~~~~~~~~~~

    很无聊啊~~~~~~~~~~~~~~~~

  • 0
    @ 2009-10-22 19:49:09

    高精度加减法呵呵,累死喽。

    Sunny测的

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    附源程序

    program P1372;

    var f:longint;

    a,b,c:array[-1..101] of integer;

    procedure init;

    var temp:char;

    i,j:longint;

    t:byte;

    begin

    fillchar(a,sizeof(a),0);

    fillchar(b,sizeof(b),0);

    fillchar(c,sizeof(c),0);

    read(temp); a[-1]:=1; a[0]:=0;

    if temp='-' then begin a[-1]:=-1; read(temp) end;

    while (temp' ') and (not eoln) do

    begin

    a[0]:=a[0]+1;

    a[a[0]]:=ord(temp)-48;

    read(temp);

    end;

    j:=a[0];

    for i:=1 to (a[0] div 2+a[0] mod 2) do

    begin

    t:=a[i];

    a[i]:=a[j];

    a[j]:=t;

    dec(j);

    end;

    read(temp); b[-1]:=1; b[0]:=0;

    if temp='-' then begin b[-1]:=-1; read(temp) end;

    b[-1]:=b[-1]*-1;

    while (not eoln) do

    begin

    b[0]:=b[0]+1;

    b[b[0]]:=ord(temp)-48;

    read(temp);

    end;

    b[0]:=b[0]+1;

    b[b[0]]:=ord(temp)-48;

    j:=b[0];

    for i:=1 to (b[0] div 2+b[0] mod 2) do

    begin

    t:=b[i];

    b[i]:=b[j];

    b[j]:=t;

    dec(j);

    end;

    end;

    procedure compare;

    var i,temp:longint;

    begin

    if a[0]>b[0] then f:=0

    else

    if a[0]0) do dec(i);

    if a[i]>b[i] then f:=0

    else

    if a[i]

  • 0
    @ 2009-10-21 10:30:02

    确实无须高精度 程序才20行

  • 0
    @ 2009-10-07 17:55:56

    做水题!锻炼身体!

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

  • 0
    @ 2009-09-26 16:10:20

    编译通过...

    ├ 测试数据 01:答案错误...

     ├ Hint: 你死定了! ├ 标准行输出

     ├ 错误行输出

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案错误...

     ├ Hint: 又死了! ├ 标准行输出

     ├ 错误行输出

    ├ 测试数据 04:答案错误...

     ├ Hint: 哈哈哈! ├ 标准行输出

     ├ 错误行输出

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Unaccepted 有效得分:2 有效耗时:0ms

  • 0
    @ 2009-09-25 14:39:17

    program ll;

    var

    x,y:qword;

    s:string;

    c:array[0..1000] of char;

    f1,f2:boolean;

    k,a1:longint;

    procedure da(x:qword);

    var

    i,j:longint;

    s:string;

    begin

    str(x,s);

    j:=3-length(s) mod 3+1;

    for i:=1 to length(s) do

    c[i]:=s[length(s)-i+1];

    for i:= length(s) downto 1 do

    begin

    if (j mod 3 =0) and (i1) then

    write(c[i],',')

    else

    write(c[i]);

    inc(j);

    end;

    end;

    begin

    readln(s);

    f1:=true;

    f2:=true;

    k:=pos(' ',s);

    if pos('-',s)=0 then

    begin

    f1:=true;

    f2:=true;

    val(copy(s,1,k-1),x);

    val(copy(s,k+1,length(s)-k),y);

    end

    else

    if pos('-',s)=y then

    da(x-y);

    if y>x then begin write('-'); da(y-x); end;

    end

    else

    if f1 and not f2 then

    da(x+y)

    else

    if f2 and (not f1) then

    begin

    write('-');

    da(x+y);

    end

    else

    if not f1 and not f2 then

    begin

    if x>y then begin write('-');da(x-y); end

    else

    da(x-y);

    end;

    end.

    为什么99分,最后一点过不去

  • 0
    @ 2009-09-20 11:31:43

    这题太水.....鉴定完毕..............

    手动判正负然后存qword类型变量里....

    多喝水有益健康!

    ---|---|-晒超级水程序了---|---|---|---|-

    var

    s:qword;

    a,b:int64;

    x,i:longint;

    s1:string;

    begin

    readln(a,b);

    if a>b then s:=a-b else

    s:=b-a;

    if a

  • 0
    @ 2009-09-14 20:06:07

    囧,140+行

    program p1372;

    var st,s1,s2,s5:string;

    t:boolean;

    p:integer;

    procedure print(s:string);

    var l,i:integer;

    begin

    l:=length(s);

    for i:=1 to l do

    begin

    write(s[i]);

    if ((l-i) mod 3=0) and (il) then write(',');

    end;

    end;

    function check(s1,s2:string):boolean;

    var l1,l2,i,k1,k2:integer;

    begin

    l1:=length(s1);

    l2:=length(s2);

    if l1l2 then exit(true);

    for i:=1 to l1 do

    begin

    val(s1[i],k1);

    val(s2[i],k2);

    if k1k2 then exit(true);

    end;

    end;

    function jian(s1,s2:string):string;

    var s:string;

    l1,l2,i,j,x:integer;

    a,b,c:array[1..100] of integer;

    begin

    l1:=length(s1);l2:=length(s2);s:='';jian:='';

    fillchar(a,sizeof(a),0);fillchar(b,sizeof(b),0);fillchar(c,sizeof(c),0);

    for i:=1 to l1 do a[l1-i+1]:=ord(s1[i])-48;

    for i:=1 to l2 do b[l2-i+1]:=ord(s2[i])-48;

    for i:=1 to l1 do

    begin

    a[i]:=a[i]-b[i];

    if a[i]=10 then

    begin

    a[i]:=a[i]-10;

    a:=a+1;

    end;

    end;

    c:=a;jia:='';s:='';

    for i:=l1+1 downto 1 do

    if c[i]0 then break;

    for j:=i downto 1 do

    begin

    str(c[j],s);

    jia:=jia+s;

    end;

    end;

    begin

    readln(st);

    p:=pos(' ',st);

    s1:=copy(st,1,p-1);

    s2:=copy(st,p+1,length(st)-p);

    if (s1[1]='-') and (s2[1]='-') then

    begin

    delete(s1,1,1);

    delete(s2,1,1);

    t:=check(s1,s2);

    if s1=s2 then

    begin

    writeln(0);

    exit;

    end;

    if t then

    begin

    s5:=jian(s1,s2);

    write('-');

    print(s5);

    exit;

    end;

    s5:=jian(s2,s1);

    print(s5);

    exit;

    end;

    if (s1[1]='-') and (s2[1]'-') then

    begin

    delete(s1,1,1);

    write('-');

    if check(s1,s2) then s5:=jia(s1,s2) else s5:=jia(s2,s1);

    print(s5);

    exit;

    end;

    if (s1[1]'-') and (s2[1]='-') then

    begin

    delete(s2,1,1);

    if check(s1,s2) then s5:=jia(s1,s2) else s5:=jia(s2,s1);

    print(s5);

    exit;

    end;

    if (s1[1]'-') and (s2[1]'-') then

    begin

    if s1=s2 then

    begin

    write(0);

    exit;

    end;

    t:=check(s1,s2);

    if t then s5:=jian(s1,s2)

    else begin

    write('-');

    s5:=jian(s2,s1);

    end;

    print(s5);

    exit;

    end;

    end.

  • 0
    @ 2009-09-06 15:35:41

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    var

    s:string;

    a,b,c:array[0..100]of longint;

    fu1,fu2,fu3:boolean;

    i,j,k:longint;

    function max(a,b:longint):longint;

    begin if a>b then exit(a);exit(b);end;

    function check:boolean;

    var i:longint;

    begin

    i:=a[0];

    if a[0]>b[0]then exit(true)else if(a[0]0)do dec(i);

    if i=0 then begin writeln(0);halt end;

    if a[i]>b[i]then exit(true);

    exit(false);

    end;

    procedure jia;

    var i:longint;

    begin

    fillchar(c,sizeof(c),0);

    for i:=1 to max(a[0],b[0])do

    begin

    c[i]:=c[i]+a[i]+b[i];

    c:=c[i]div 10;

    c[i]:=c[i]mod 10;

    end;

    c[0]:=i+2;

    while c[c[0]]=0 do dec(c[0]);

    end;

    procedure jian;

    begin

    if not(check)then begin fu3:=true;c:=a;a:=b;b:=c;end;

    fillchar(c,sizeof(c),0);

    for i:=1 to a[0]do

    begin

    c[i]:=c[i]+a[i]-b[i];

    if c[i]1)do dec(a[0]);

    while (b[b[0]]=0)and(b[0]>1)do dec(b[0]);

    if (fu1 xor fu2)then

    begin

    jia;

    if (not(fu1))and(fu2)then

    for i:=c[0]downto 1 do

    begin

    write(c[i]);

    if ((i-1)mod 3=0)and(i1)then write(',');

    end

    else begin

    write('-');

    for i:=c[0]downto 1 do

    begin

    write(c[i]);

    if ((i-1)mod 3=0)and(i1)then write(',');

    end

    end;

    end

    else begin

    jian;

    if ((not(fu1))and(not(fu2))and(not(fu3)))or(fu1 and fu2 and fu3)then

    for i:=c[0]downto 1 do

    begin

    write(c[i]);

    if ((i-1)mod 3=0)and(i1)then write(',');

    end

    else begin

    write('-');

    for i:=c[0]downto 1 do

    begin

    write(c[i]);

    if ((i-1)mod 3=0)and(i1)then write(',');

    end

    end;

    end;

    writeln;

    end.

    117行,其实处理部分完全可以写得更简练,但是我懒得想了,这种程序有意思么。。。

    Once AC

    权当刷屏吧。。。很多部分我写的时候就是复制粘贴的,一般很长很菜的程序都源于复制和粘贴。

  • 0
    @ 2009-09-05 01:13:46

    编译通过...

    ├ 测试数据 01:答案正确... 0ms

    ├ 测试数据 02:答案正确... 0ms

    ├ 测试数据 03:答案正确... 0ms

    ├ 测试数据 04:答案正确... 0ms

    ├ 测试数据 05:答案正确... 0ms

    ---|---|---|---|---|---|---|---|-

    Accepted 有效得分:100 有效耗时:0ms

    啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊,高精度一定要扎实,不然像我交了N次才过~T_T

    program ddf;

    type

    arr=array[0..100]of integer;

    var

    b1,b2:arr;

    x,i:integer;

    s,s1,s2:string;

    zf1,zf2,zf3:boolean;

    procedure pp(x,y:arr);

    var

    z:arr;

    i,ss:integer;

    begin

    zf3:=false;

    if (x[0]

  • 0
    @ 2009-08-25 12:45:40

    高精加和高精减都用了

    AC

  • 0
    @ 2009-08-22 00:26:40

    112行的,三次AC

    AC率差点下降了一个点。。。

    用高精的话一定要分类讨论。。。。。。。

    程序太长了额额额额额额额额额

    =======================晒程序=========================

    http://lifeich1.spaces.live.com/blog/cns!9AB465A9D807BE22!128.entry

信息

ID
1372
难度
6
分类
模拟 点击显示
标签
递交数
1675
已通过
453
通过率
27%
被复制
4
上传者