📄 serial.pas
字号:
{
PROG:serial
LANG:PASCAL
}
program serial;
var
fin,fout:text;
bully,minvictim,v:string;
half,i:integer;
function count(s:string;x:char):integer;
var
i:integer;
begin
count:=0;
for i:=1 to length(s) do
if s[i]=x then inc(count);
end;
function makestr(l:integer;c:char):string;
var
i:integer;
begin
makestr:='';
for i:=1 to l do
makestr:=makestr+c;
end;
function victim(x:char):string;
var
p,i:integer;
overflow:boolean;
procedure plus(w:integer);
begin
if w=0 then begin
overflow:=true;
exit;
end
else if victim[w]='9' then begin
victim[w]:='0';
plus(w-1);
end
else
inc(victim[w]);
end;
begin
victim:=bully;
p:=length(victim);
while count(victim,x)<=half do begin
if victim[p]>x then begin
overflow:=false;
plus(p-1);
if overflow then begin
victim:=makestr(length(victim),'9');
exit;
end;
end;
victim[p]:=x;
dec(p);
end;
for i:=p+1 to p+count(victim,x)-half-1 do
victim[i]:='0';
end;
begin
assign(fin,'serial.in');
reset(fin);
readln(fin,bully);
close(fin);
half:=length(bully) div 2;
minvictim:=victim('0');
for i:=1 to 9 do begin
v:=victim(chr(48+i));
if v<minvictim then minvictim:=v;
end;
assign(fout,'serial.out');
rewrite(fout);
writeln(fout,minvictim);
close(fout);
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -