character*10::A,B character::numa,numb integer::lena,lenb,i read *,A,B lena = LEN_TRIM(A) lenb = LEN_TRIM(B) if(lena.gt.lenb) then print '(a)', TRIM(A) else if(lenb.gt.lena) then print '(a)', TRIM(B) else do i=1,lena numa = A(i:i) numb = B(i:i) if(numa.eq.numb) cycle if(numa.eq.'7' .and. numb.eq.'4') then print '(a)', TRIM(B) exit else if(numa.eq.'4' .and. numb.eq.'7') then print '(a)', TRIM(A) exit else if(numa.gt.numb) then print '(a)', TRIM(A) exit else print '(a)', TRIM(B) exit end if end do end if end program