a:array[1..10]of integer{10个数}
u:array[1..10]of boolean{记录每个数是否被使用}
b,c:array[1..5]of integer{分成两个数,每个数最多5位}
i,j,k,l,m,n,x,y:longint
function getmin:integer{取最小}
var o,p:integer
begin
getmin:=maxint
for o:=1 to n do if u[o] and (a[o]<getmin) then begin
getmin:=a[o]
p:=o
end
u[p]:=false
dec(m)
end
function getmax:integer{取最大}
var o,p:integer
begin
getmax:=-maxint
for o:=1 to n do if u[o] and (a[o]>getmax) then begin
getmax:=a[o]
p:=o
end
u[p]:=false{取过的数封掉}
dec(m)
end
procedure work
begin
while m>0 do
begin
inc(k)
b[k]:=getmin{大数取小}
inc(l)
c[l]:=getmax{小数取大}
end
end
procedure print(p:integer)
begin
j:=1
m:=0
n:=0
for i:=p downto 1 do begin inc(m,b[i]*j)inc(n,c[i]*j)j:=j*10end
writeln(m-n)
end
begin
readln(n)
for i:=1 to n do read(a[i])
readln
for i:=1 to n-1 do
for j:=i+1 to n do if a[i]>a[j] then begin k:=a[i]a[i]:=a[j]a[j]:=kend{选择排序(从小到大)}
if a[n-1]=0 then begin for i:=n downto 2 do write(a[i])writelnexitend{如果只有1个数不为零,直接输答案}
m:=maxint
for i:=1 to n-1 do if (a[i+1]-a[i]<m)and(a[i]<>0) then
begin
m:=a[i+1]-a[i]
l:=i
end{取相差最小的两数}
if m=maxint then
for i:=1 to n-1 do if (a[i+1]-a[i]<m) then
begin
m:=a[i+1]-a[i]
l:=i
end
x:=a[l]
y:=a[l+1]
fillchar(u,sizeof(u),true)
m:=n-2
if odd(n) then begin {奇数情况}
for i:=1 to n do if a[i]<>0 then begin b[1]:=a[i]u[i]:=falsebreakend{大数首位(大数比小数多一位)取最小数,小数取0}
c[1]:=0
k:=1{大数计算了的位数}
l:=1{小数}
work{主程序}
print(n div 2+1){输出}
end else
begin{偶数情况}
u[l]:=false
u[l+1]:=false
b[1]:=y
c[1]:=x
k:=1
l:=1
work
print(n div 2)
end
end.
{原创,刚才写了下,应该可以AC,希望采纳}
{如样例,1634,取最接近3,4,然后大数取小4取1,3取6,如此类推,得36和41}
{奇数时,如1 5 9 6 1,大数取小1,1,5,小数取大,9,6,即可}
Local date2,date1date2 = ctod('2014-12-19')
date1 = ctod('2014-10-20')
if (date2-date1)<30 then
messagebox('相差'+transform(date2-date1)+'天')
else
if MOD(date2-date1,30) = 0 then
messagebox('相差'+transform(Floor((date2-date1)/30))+'个月')
else
messagebox('相差'+transform(Floor((date2-date1)/30))+'个月'+transform(MOD(date2-date1,30))+'天')
endif
endif
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)