TAT 去年NOIP第一题有两个点不过,求大牛解释~谢
我的程序:varm,n,i,j,s,top,x:integer;a:array[1..1000]ofinteger;flag:boolean;beginreadln(m,...
我的程序:
var m,n,i,j,s,top,x:integer;
a:array[1..1000] of integer;
flag:boolean;
begin
readln(m,n);
top:=1;
x:=0;
for i:=1 to 1000 do a[i]:=-1;
for i:=1 to n do begin
read(s);
flag:=false;
for j:=1 to m do if a[j]=s then begin
flag:=true;
break;
end;
if (top<m) and (not(flag)) then begin
x:=x+1;
top:=top+1;
a[top]:=s
end
else if not(flag) then
begin
x:=x+1;
for j:=1 to top-1 do
begin
a[j]:=a[j+1];
a[top]:=s
end
end;
end;
writeln(x);
end. 展开
var m,n,i,j,s,top,x:integer;
a:array[1..1000] of integer;
flag:boolean;
begin
readln(m,n);
top:=1;
x:=0;
for i:=1 to 1000 do a[i]:=-1;
for i:=1 to n do begin
read(s);
flag:=false;
for j:=1 to m do if a[j]=s then begin
flag:=true;
break;
end;
if (top<m) and (not(flag)) then begin
x:=x+1;
top:=top+1;
a[top]:=s
end
else if not(flag) then
begin
x:=x+1;
for j:=1 to top-1 do
begin
a[j]:=a[j+1];
a[top]:=s
end
end;
end;
writeln(x);
end. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询