program main implicit none character*300::S character*300::SR integer::i,len character::c S="" SR="" read *, S len = LEN_TRIM(S) i = 1 do if(i.gt.len) exit c = S(len-i+1:len-i+i) if(is_ascii(c)) then SR(i:i) = c i = i + 1 else SR(i:i+2) = S(len-i-1:len-i+1) i = i + 3 end if end do print '(a)', TRIM(SR) return contains logical function is_ascii(c) result(l) character::c l = IACHAR(c).le.127 end function is_ascii end program main