本文介绍了如何扭转一个字符链?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须创建一个逆转短语的程序.
I have to create a program that reverses phrases.
例如:当我写 hello guys
时,我想要 syug olleh
For example: when I write hello guys
, I want syug olleh
这是我目前所拥有的,但是我不知道如何反转面板中的字符 phraseT
:
This is what I have for the moment but I don't know how to reverse the characters in the board phraseT
:
program reversing
implicit none
character(len=20),dimension(1:20)::phraseT
character(len=20)::phrase,reverse
integer::i,x
write(*,*)"write a phrase :"
read(*,'(a)')phrase
x=len(trim(phrase))
nomT(1:20)=" "
do i=1,x
nomT(i:i)=trim(phrase(i:i))
end do
write(*,*)nomT
end program reversing
推荐答案
一种简单的方法...
One simple way to do it ...
character(80) :: string = "Whatttt's up doc?"
character :: temp
integer :: i, length
write (*,*) string ! Writes it out proper.
length = len_trim(string) ! ignores trailing blanks.
! use len(string) to reverse those as well
do i = 1, length/2
temp = string(i:i)
string(i:i) = string(length+1-i:length+1-i)
string(length+1-i:length+1-i) = temp
end do
write(*,*) string ! Writes it out backwards.
end
其他人肯定会提出更多(或更短)的建议.
Others will come up with more intelligent ones (and shorter) for sure.
这篇关于如何扭转一个字符链?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!