program main implicit none character*9::N character::c integer::digits(9) integer::i,j,k,len,resmax data digits/9*0/ read *,N len = LEN_TRIM(N) do i=1,len digits(i) = ICHAR(N(i:i))-ICHAR('0') end do ! print *,digits(1:len) ! return do i=1,len-1 resmax = MAXVAL(digits(i+1:len)) if(resmax.gt.digits(i)) then do j=len,i,-1 if(resmax.eq.digits(j)) then digits(j) = digits(i) digits(i) = resmax goto 100 end if end do end if end do 100 continue do i=1,len write (*,'(i0)',advance='no') digits(i) end do write(*,*) end program main