Algorithm 如何使单词处于大写的偶数位置?

Algorithm 如何使单词处于大写的偶数位置?,algorithm,eiffel,Algorithm,Eiffel,这是我的eiffel程序,它基本上是删除给定文本文件中的多余空格,以遵循常规的expresson:a+SA+*EOL,其中文件中的每一行必须以字母开头,字母之间只能有一个空格 我的问题是,在这个程序的基础上,我如何扩展它,使每个单词都成为大写?i、 e.第二、第四、第六等 feature {NONE} -- Main routine copy_file -- Copy a file character by character from input to output require

这是我的eiffel程序,它基本上是删除给定文本文件中的多余空格,以遵循常规的expresson:a+SA+*EOL,其中文件中的每一行必须以字母开头,字母之间只能有一个空格

我的问题是,在这个程序的基础上,我如何扩展它,使每个单词都成为大写?i、 e.第二、第四、第六等

feature {NONE} -- Main routine

copy_file
    -- Copy a file character by character from input to output
require
input_open: input.is_readable
output_open: output.is_writable
local flag: INTEGER
has_read_space: BOOLEAN
empty_line : BOOLEAN
do
empty_line: True
flag := 0       -- 0 for previous space, 1 for previous char
from read_char  -- Must prime the pump by reading the first character
until ch = EOF
loop
    from
        ch := input.last_character
    until
        ch = EOL
    loop
        if ch = Space_char and flag = 0 then        -- leading spaces
            read_char
        elseif ch /= Space_char and flag = 0 then   -- see first    charater after space
            if has_read_space then          -- this clause make sure the space will only place in between two words instead of end of lin
               output.putchar (Space_char)
            end
            output.putchar (ch)
            empty_line := False
            flag := 1
            read_char
        elseif ch = Space_char and flag = 1 then    -- see space after characters
            has_read_space := True          -- Don't output it right away
            flag := 0
            read_char
        elseif ch /= Space_char and flag = 1  then  -- see character after character
            output.putchar (ch)
            read_char
        end
    end
    if empty_line = False then
        output.putchar (EOL)        -- if line is not empty, then we place EOL at the end of line
    end
    flag := 0       -- reset it to 0 to make sure the next follow the same routine
    has_read_space := False -- reset it to avoid placing space in the beginning of line
    empty_line := True  -- reset to proceed to new line
    read_char
end

  -- At end of file, nothing to do in Eiffel except close the files
input.close
output.close
end
我刚想出来。 只需设置另一个标志,比如evenWord,将其初始化为false。
在elseif ch=Space\u char and flag=1子句中,翻转标志evenWord:=not evenWord It work

你能正确缩进它吗,然后我就可以读它了。似乎有两种方法:2重新排列输入-如果超过一半的单词是小写的,那么很困难。