假如程序输入的n个数据是放在N数组中的. 程序如下
var
i,j:Integer; //循环变量
Len:Integer; //数组N的长度
Tmp:Integer; //临时数据
TmpStr:String; //临时数据
MaxNum:Integer; //你想要得到的数
Begin
Len:=High(N);
For i:=0 to Len-1 do
For j:=0 to Len-i-1 do
Begin
If StrToInt(Copy(IntToStr(N[j]),1,1))<StrToInt(Copy(IntToStr(N[j+1]),1,1)) Then
Begin
Tmp:=N[j];
N[j]:=N[j+1];
N[j+1]:=Tmp;
End;
End;
For i:=0 to Len Do
Begin
TmpStr:=TmpStr+IntToStr(N[i]);
End;
MaxNum:=StrToInt(TmpStr); //这是你想得到的数
End;其实这个算法就是课本上的冒泡排序法.只是你要把排序的数不是整个数,而是每个数字的第一位而已.
var
i,j:Integer; //循环变量
Len:Integer; //数组N的长度
Tmp:Integer; //临时数据
TmpStr:String; //临时数据
MaxNum:Integer; //你想要得到的数
Begin
Len:=High(N);
For i:=0 to Len-1 do
For j:=0 to Len-i-1 do
Begin
If StrToInt(Copy(IntToStr(N[j]),1,1))<StrToInt(Copy(IntToStr(N[j+1]),1,1)) Then
Begin
Tmp:=N[j];
N[j]:=N[j+1];
N[j+1]:=Tmp;
End;
End;
For i:=0 to Len Do
Begin
TmpStr:=TmpStr+IntToStr(N[i]);
End;
MaxNum:=StrToInt(TmpStr); //这是你想得到的数
End;其实这个算法就是课本上的冒泡排序法.只是你要把排序的数不是整个数,而是每个数字的第一位而已.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货