主题:打印
wenjb
[专家分:0] 发布于 2008-10-04 18:45:00
1.输入三个数,按由大到小的顺序打印出来。
2.计算1901年至2099年之间的某年某月星期几。
3.求s=1+4+7+...+298的值。
4.编写一个评分程序,接受用户输入10各选手的得分(0-10分),然后去掉一个最高分和一个最低分,求出某选手的最后得分(平均分)。
5.用一张一元票换1分、2分、5分的硬币,每种至少一枚,问有几种换法(各几枚)?
沙发
小田甜 [专家分:3910] 发布于 2008-10-05 13:16:00
第一题:
var
a:array [1..3] of integer;
i,j:byte;
begin
for i:=1 to 3 do read(a[i]);
for i:=1 to 2 do for j:=i+1 to 3 do
if a[i]<a[j] then begin
a[i]:=a[i]+a[j];
a[j]:=a[i]-a[j];
a[i]:=a[i]-a[j];
end;
for i:=1 to 3 do writeln(a[i]);
end.
第二题:
基本上就是从一天开始一天一天的数.
我定义的19901101是因为——我生日嘛~
const
g:array [0..6] of string[9]
=('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
var
xingqi:word;
tn,ty,tr:word;
function y(n:word):word;
begin
y:=365+ord(((n mod 4=0) and
(n mod 100<>0)) or (n mod 400=0));
end;
function m(n:word;u:byte):byte;
const
e:array [1..12] of byte
=(31,28,31,30,31,30,31,31,30,31,30,31);
begin
m:=e[u]+ord((u=2) and (y(n)=366));
end;
function StrToInt(s:string):integer;
var Code,V:integer;
begin
Val(s,V,Code);
StrToInt:=V;
end;
function Date(tn,ty,tr:word;var xingqi:word):LongInt;
var
nian,yue,ri,i:word;
begin
nian:=1990;yue:=11;ri:=1;xingqi:=4;
while nian<>tn do begin
if nian<tn then begin
inc(nian);
xingqi:=(xingqi+y(nian)-364) mod 7;
end else begin
xingqi:=(xingqi-y(nian)+371) mod 7;
dec(nian);
end;
end;
while yue<>ty do begin
if yue<ty then begin
xingqi:=(xingqi+m(nian,yue)-28) mod 7;
inc(yue);
end else begin
dec(yue);
xingqi:=(xingqi-m(nian,yue)+35) mod 7;
end;
end;
ri:=tr;xingqi:=(xingqi+ri-1) mod 7;
end;
procedure inputdate(var tn,ty,tr:word);
var
s:string;
function h(s:string):boolean;
var
flag:boolean;i:byte;
begin
flag:=length(s)=8;
if flag then
for i:=1 to 8 do
if not (s[i] in ['0'..'9']) then flag:=false;
h:=flag;if not flag then writeln('Input Error!');
end;
function z:boolean;
var
flag:boolean;
begin
flag:=true;
if (ty>12) or (ty<1) then flag:=false;
if (tr>m(tn,ty)) or (tr<1) then flag:=false;
z:=flag;if not flag then writeln('Date NOT exist!');
end;
begin
repeat
repeat
write('Input Date As "YYYYMMDD":');
readln(s);
until h(s);
tn:=StrToInt(copy(s,1,4));
ty:=StrToInt(copy(s,5,2));
tr:=StrToInt(copy(s,7,2));
until z;
end;
begin
InputDate(tn,ty,tr);
Date(tn,ty,tr,xingqi);
writeln(tn,'.',ty,'.',tr,':',g[xingqi],'(',xingqi,')');
readln;
end.
第三题:
{s=1+4+7+...+298}
var
i,s:word;
begin
for i:=1 to 300 do begin
s:=s+i;
i:=i+2;
end;
writeln(s);
end.
第四题:
var
i,scr,max,min,total:byte;
begin
read(scr);
max:=scr; min:=scr; total:=scr;
for i:=2 to 10 do begin
read(scr);
if scr>max then max:=scr;
if scr<min then min:=scr;
total:=total+scr;
end;
write((total-min-max)/8:5:3);
end.
第五题:
var
a,b,c:byte;
begin
a:=0;
for c:=1 to 19 do begin
for b:=1 to (100-c*5) div 2 do begin
writeln(100-5*c-2*b:5,b:5,c:5);
a:=a+1;
end;
readln;
end;
writeln('Total=',a);
readln;
end.