Thứ Năm, 19 tháng 5, 2022

XOACHUSO PASCAL

program bai1; // 75% xet moi truong hop trong O(n^2), 100% trong O(n)
const nm = 100000;
var
    s: ansistring;
    n, k, top: longint;
    stack: array[1..nm] of char;
procedure nhap;
begin
readln(s);
     readln(k);
     n := length(s);
end;

procedure push(x:longint);
begin
    inc(top);stack[top]:=x;
end;

procedure sol;
var    i: longword;
begin
n := length(s);top:=0;
push(s[1]);
     for i := 2 to n do
     begin
             while (k > 0) and (top > 0) and (stack[top] < s[i]) do
           begin
                 dec(k);dec(top);
           end;
           push(s[i]);
     end;
     for i := 1 to (top-k) do write(stack[i]);
end;
begin
    assign(input, 'xoacs.inp'); reset(input);
    assign(output, 'xoacs.out'); rewrite(output);
    nhap;
    sol;
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.