Thứ Sáu, 13 tháng 5, 2022

HECOSO Pascal

var kq:int64;
    i,r,test,t:longint;
    a,b,s:string;
    m:array[0..10] of string;


procedure tach_so;
var d,code:longint;

begin
    for i:=1 to 3 do m[i]='';
    d:=1;
    for i:=1 to length(s) do
        if s[i]<>' ' then m[d]:=m[d]+s[i]
        else inc(d);
    a:=m[1];b:=m[2];
    val(m[3],r,code);
end;

function doi10(s:string):int64;
var res:int64;
    i,x,n:longint;
    p:array[0..20] of longint;
begin
    res:=0;
    n:=length(s);
    p[0]:=1;
    for i:=1 to n do p[i]:=p[i-1]*r;
    for i:=1 to n do
    begin
        if s[i]<'A' then x:=ord(s[i])-48
        else x:=ord(s[i])-55;
        res:=res+p[n-i]*x;
    end;
    exit(res);
end;

function doir(n:longint):string;
var s:string;
    x:longint;
begin
    if n=0 then exit('0');
    s:='';
    while n>0 do
    begin
        x:=n mod r;
        if x<10 then s:=chr(x+48)+s
        else s:=chr(x+55)+s;
        n:=n div r;
    end;
    exit(s);
end;

procedure giai;
var d1,a1,b1,c1:int64;
    c,d:string;

begin
    a1:=doi10(a);
    b1:=doi10(b);
    c1:=a1+b1;
    d1:=a1-b1;
    //writeln(a1,' ',b1,' ',c1);
    c:=doir(c1);
    d:=doir(d1);
    writeln(c,' ',d);
end;

begin
    assign(input,'hecoso.inp');reset(input);
    assign(output,'hecoso.out');rewrite(output);
    readln(test);
    for t:=1 to test do
    begin
        readln(s);
        tach_so;
      //  writeln(a,' ',b,' ',r);
        giai;
    end;
end.

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.