主题:各位哥哥多指教呀!!!
			 taofei
				 [专家分:30]  发布于 2005-07-08 19:01:00
 taofei
				 [专家分:30]  发布于 2005-07-08 19:01:00							
			输入一个五位数
然后用这五个数字组成最大的数,再组成最小的数相减
输出结果
怎么才能最简单呀
						
					 
		
			
回复列表 (共9个回复)
		
								
				沙发
				
					 zhsas [专家分:1680]  发布于 2005-07-20 01:58:00
zhsas [专家分:1680]  发布于 2005-07-20 01:58:00				
				过了十多天了还没有人回呀?你自己做出来了吗?和我做的有什么不同吗?
program zhs (input,output);
  const
    n=5;
  var
    num,x,y,temp,i,j:longint;
    a:array[1..n] of integer;
    flag:boolean;
  begin
    write('Please input number of five digit:');
    read(num);
    for i:=1 to n do
      begin
        a[i]:=num mod 10;
        num:=num div 10
      end;
    i:=1;
    repeat
      flag:=true;
      for j:=1 to n-i do
        if a[j] < a[j+1]
          then begin
                 temp:=a[j];
                 a[j]:=a[j+1];
                 a[j+1]:=temp;
                 flag:=false
               end;
      i:=i+1
    until flag;
    temp:=10000;
    x:=0;
    for i:=1 to n do
      begin
        x:=x+a[i]*temp;
        temp:=temp div 10
      end;
    temp:=10000;
    y:=0;
    for j:=n downto 1 do
      begin
        y:=y+a[j]*temp;
        temp:=temp div 10
      end;
    writeln('max=',x,'':6,'min=',y,'':6,'result=',x-y)
  end.
							 
						
				板凳
				
					 口口and枕头 [专家分:1550]  发布于 2005-07-20 02:57:00
口口and枕头 [专家分:1550]  发布于 2005-07-20 02:57:00				
				这个我想到一个更简单的方法~我过两天回来了再说`\~~
							 
						
				3 楼
				
					 口口and枕头 [专家分:1550]  发布于 2005-07-23 01:00:00
口口and枕头 [专家分:1550]  发布于 2005-07-23 01:00:00				
				哎~~~
我本来是想用查表的方法来解决排序的问题~~~~~~
但细想这种方法只适用于五个数不同的情况~~~~~~
							 
						
				4 楼
				
					 sd5774188 [专家分:260]  发布于 2005-07-25 21:49:00
sd5774188 [专家分:260]  发布于 2005-07-25 21:49:00				
				我的:
program yb(input,output);
 var yuanshu:string;
     max:longint;
     min:longint;
     s,s1:string;
     i,j:integer;
     code:integer;
     ch:char;
 begin
  readln(yuanshu);
  s:=yuanshu;s1:=yuanshu;
  for i:=1 to length(yuanshu)-1 do
   for j:=1 to length(yuanshu)-i do begin
    if s[j]<s[j+1] then
     begin
      ch:=s[j];
      s[j]:=s[j+1];
      s[j+1]:=ch;
     end;
    if s1[j]>s1[j+1] then
     begin
      ch:=s1[j];
      s1[j]:=s1[j+1];
      s1[j+1]:=ch;
     end;
    end;
  val(s,max,code);
  val(s1,min,code);
  writeln(max,'-',min,'=',max-min);
 end.
							 
						
				5 楼
				
					 口口and枕头 [专家分:1550]  发布于 2005-07-26 17:56:00
口口and枕头 [专家分:1550]  发布于 2005-07-26 17:56:00				
				请问如果楼上的,如果输入的数有0这种情况怎么办.你的程序好像不能满足~~~
嘿嘿~~
							 
						
				6 楼
				
					 delphi6 [专家分:3450]  发布于 2005-07-26 19:55:00
delphi6 [专家分:3450]  发布于 2005-07-26 19:55:00				
				
[img]http://bbs.cqreview.com/UploadFile/2005-7/2005712154831382.gif[/img]
							 
						
				7 楼
				
					 taofei [专家分:30]  发布于 2005-07-30 18:44:00
taofei [专家分:30]  发布于 2005-07-30 18:44:00				
				也许我还没学到那吧
我还不能接受,不过我相信你们写的都是好的,谢谢大家,55555555555555
							 
						
				8 楼
				
					 zhsas [专家分:1680]  发布于 2005-07-30 23:08:00
zhsas [专家分:1680]  发布于 2005-07-30 23:08:00				
				这金棒好烦人............................................................
要滚40多下才能滚完这个烦人的棒...............................................
							 
						
				9 楼
				
					 口口and枕头 [专家分:1550]  发布于 2005-07-30 23:26:00
口口and枕头 [专家分:1550]  发布于 2005-07-30 23:26:00				
				我还专门发了贴说他的~
他还是这样~~没办法~~~
							 
									
			
我来回复