求noip2007普及组复赛试题及答案

主要是答案,试题可有可无.
(谢谢拉```要pascal的 哈~~)....

第一题
program scholar(input,output);
var a,b,c,id,s:array[1..300]of integer;v:array[0..0]of boolean;
i,j,k,t,m,n,x,y:integer;
begin
assign(input,'scholar.in');
assign(output,'scholar.out');
reset(input);rewrite(output);
readln(n);
for i:=1 to n do
begin readln(a[i],b[i],c[i]);id[i]:=i;end;
for i:=1 to n do
s[i]:=a[i]+b[i]+c[i];
for i:=1 to n-1 do
for j:=i to n do
begin
if s[i]<s[j]then
begin
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=a[i];a[i]:=a[j];a[j]:=t;
t:=b[i];b[i]:=b[j];b[j]:=t;
t:=c[i];c[i]:=c[j];c[j]:=t;
t:=id[i];id[i]:=id[j];id[j]:=t;
end;
if s[i]=s[j]then
if a[i]<a[j] then
begin
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=a[i];a[i]:=a[j];a[j]:=t;
t:=b[i];b[i]:=b[j];b[j]:=t;
t:=c[i];c[i]:=c[j];c[j]:=t;
t:=id[i];id[i]:=id[j];id[j]:=t;
end
end;
for i:=1 to 5 do
writeln(id[i],' ',a[i]+b[i]+c[i]);
close(input);close(output);
end.

第二题
program group(input,output);
var
s,i,w,n:integer;
a:array[1..30000] of integer;
procedure sort_quick(l,r:integer);
var i,j,x,y:integer;
begin

i:=l;j:=r;
x:=a[(l+r)div 2];
repeat
while a[i]<x do inc(i);
while x<a[j] do dec(j);
if i<=j then
begin y:=a[i];a[i]:=a[j];a[j]:=y;inc(i);dec(j); end;
until i>j;
if i<r then sort_quick(i,r);
if l<j then sort_quick(l,j);
end;
begin
assign(input,'group.in');
assign(output,'group.out');
reset(input);rewrite(output);
readln(w);readln(n);
for i:=1 to n do
readln(a[i]);
sort_quick(1,n);
i:=1;s:=0;
repeat
if a[i]+a[n]<=w then begin s:=s+1;inc(i);dec(n);end
else begin s:=s+1;dec(n);end;

until i>n;
writeln(s);
close(input);
close(output);
end.

第三题
还没做出来
第四题
program hanoi(input,output);
var n,i:integer;
s:string;
function twox(var ss:string):string;
var
i,j:integer;
sss:string;
begin
ss:='0'+ss;
sss:=ss;

i:=length(ss);
for j:=1 to i do
begin
if ss[j+1]>'4' then
case ss[j] of
'0','5':sss[j]:='1';
'1','6':sss[j]:='3';
'2','7':sss[j]:='5';
'3','8':sss[j]:='7';
'4','9':sss[j]:='9';
end;
if ss[j+1]<'5' then
case ss[j] of
'0','5':sss[j]:='0';
'1','6':sss[j]:='2';
'2','7':sss[j]:='4';
'3','8':sss[j]:='6';
'4','9':sss[j]:='8';
end;
end;
if sss[1]='0' then
begin
sss[1]:=' ';
delete(sss,1,1);
end;
twox:=sss;
end;

begin
assign(input,'hanoi.in');
assign(output,'hanoi.out');
reset(input);rewrite(output);
readln(n);
s:='1';
for i:=1 to n+1 do
s:=twox(s);
i:=length(s);
s[i]:=chr(ord(s[i])-2);

writeln(s);

close(input);close(output);
end.
温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-07-01
第一题
program
scholar(input,output);
var
a,b,c,id,s:array[1..300]of
integer;v:array[0..0]of
boolean;
i,j,k,t,m,n,x,y:integer;
begin
assign(input,'scholar.in');
assign(output,'scholar.out');
reset(input);rewrite(output);
readln(n);
for
i:=1
to
n
do
begin
readln(a[i],b[i],c[i]);id[i]:=i;end;
for
i:=1
to
n
do
s[i]:=a[i]+b[i]+c[i];
for
i:=1
to
n-1
do
for
j:=i
to
n
do
begin
if
s[i]<s[j]then
begin
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=a[i];a[i]:=a[j];a[j]:=t;
t:=b[i];b[i]:=b[j];b[j]:=t;
t:=c[i];c[i]:=c[j];c[j]:=t;
t:=id[i];id[i]:=id[j];id[j]:=t;
end;
if
s[i]=s[j]then
if
a[i]<a[j]
then
begin
t:=s[i];s[i]:=s[j];s[j]:=t;
t:=a[i];a[i]:=a[j];a[j]:=t;
t:=b[i];b[i]:=b[j];b[j]:=t;
t:=c[i];c[i]:=c[j];c[j]:=t;
t:=id[i];id[i]:=id[j];id[j]:=t;
end
end;
for
i:=1
to
5
do
writeln(id[i],'
',a[i]+b[i]+c[i]);
close(input);close(output);
end.
第二题
program
group(input,output);
var
s,i,w,n:integer;
a:array[1..30000]
of
integer;
procedure
sort_quick(l,r:integer);
var
i,j,x,y:integer;
begin
i:=l;j:=r;
x:=a[(l+r)div
2];
repeat
while
a[i]<x
do
inc(i);
while
x<a[j]
do
dec(j);
if
i<=j
then
begin
y:=a[i];a[i]:=a[j];a[j]:=y;inc(i);dec(j);
end;
until
i>j;
if
i<r
then
sort_quick(i,r);
if
l<j
then
sort_quick(l,j);
end;
begin
assign(input,'group.in');
assign(output,'group.out');
reset(input);rewrite(output);
readln(w);readln(n);
for
i:=1
to
n
do
readln(a[i]);
sort_quick(1,n);
i:=1;s:=0;
repeat
if
a[i]+a[n]<=w
then
begin
s:=s+1;inc(i);dec(n);end
else
begin
s:=s+1;dec(n);end;
until
i>n;
writeln(s);
close(input);
close(output);
end.
第三题
还没做出来
第四题
program
hanoi(input,output);
var
n,i:integer;
s:string;
function
twox(var
ss:string):string;
var
i,j:integer;
sss:string;
begin
ss:='0'+ss;
sss:=ss;
i:=length(ss);
for
j:=1
to
i
do
begin
if
ss[j+1]>'4'
then
case
ss[j]
of
'0','5':sss[j]:='1';
'1','6':sss[j]:='3';
'2','7':sss[j]:='5';
'3','8':sss[j]:='7';
'4','9':sss[j]:='9';
end;
if
ss[j+1]<'5'
then
case
ss[j]
of
'0','5':sss[j]:='0';
'1','6':sss[j]:='2';
'2','7':sss[j]:='4';
'3','8':sss[j]:='6';
'4','9':sss[j]:='8';
end;
end;
if
sss[1]='0'
then
begin
sss[1]:='
';
delete(sss,1,1);
end;
twox:=sss;
end;
begin
assign(input,'hanoi.in');
assign(output,'hanoi.out');
reset(input);rewrite(output);
readln(n);
s:='1';
for
i:=1
to
n+1
do
s:=twox(s);
i:=length(s);
s[i]:=chr(ord(s[i])-2);
writeln(s);
close(input);close(output);
end.
相似回答