在一个字符串中移动一个单词,其中空格作为单词之间的分隔符

Fih*_*hop 3 c c++ string

让我用一个例子更详细地解释我的问题.

给定一个字符串:

"在几个连续的单词开头,辅音是重复相同的元音"

如果我们想将第四个单词(重复单词)移动到第二个单词的位置,则该字符串将变为:

"辅音重复是几个连续单词开头的同一个元音"

给定一个C原型如下的函数:

void move(char *s, int word_begin_ind, int word_end_ind, int target_begin_ind)
Run Code Online (Sandbox Code Playgroud)

如何实现这个功能来完成这项工作?

在上面的例子中, word_begin_ind = 17, word_end_ind = 27, target_begin_ind = 10

这不是作业.实际上这是一个面试问题.我有一个算法.基本思路如下:

(1)使用word_begin_ind和制作目标词的副本word_end_ind.

(2)从target_begin_indword_begin_ind - 1,每个字符移动到正确的位置.例如,移到word_begin_ind-1'word_end_ind',word_begin_ind-2'word_end_ind-1'等等.

(3)最后,将副本移动到正确的位置(从target_begin_ind开始).

我希望每个人都能理解我的要求.

您不需要使用c来完成这项工作.C++也很受欢迎.

谁能帮我找到其他解决方案?

hat*_*ine 8

  1. 从一个位置的开始到另一个位置的结束之间的范围:

    "Assonance [is the reiteration] of the same vowel sound at the beginning of several consecutive words"
    
    Run Code Online (Sandbox Code Playgroud)
  2. 反转此范围:

    "Assonance [noitaretier eht si] of the same vowel sound at the beginning of several consecutive words"
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将此范围拆分为单词和其他所有内容:

    "Assonance [noitaretier|eht si] of the same vowel sound at the beginning of several consecutive words"
    
    Run Code Online (Sandbox Code Playgroud)
  4. 反向词:

    "Assonance [reiteration|eht si] of the same vowel sound at the beginning of several consecutive words"
    
    Run Code Online (Sandbox Code Playgroud)
  5. 扭转一切 - 其他:

    "Assonance [reiteration|is the] of the same vowel sound at the beginning of several consecutive words"
    
    Run Code Online (Sandbox Code Playgroud)
  6. 所以你已经完成了.