尝试编写代码来更正由内而外编写的字符串句子

Trying to write a code the corrects a string sentence that is written inside out

本文关键字:由内而外 字符串 句子 代码      更新时间:2023-10-16

我是一名软件工程专业的学生,我需要一些帮助来完成我被分配的作业我需要一个代码来纠正从内到外写的句子例;我喜欢编程RP evol i gnimmargo

(我的意思是内到外....句子被切成两半,每一半被翻转)我需要纠正打乱的句子

我已经通过计算用户输入的字符串中的租船人并剪切句子来开始它......但我只是不知道如何翻转每一半然后加入它们任何想法??

#include <iostream>
#include <string>
using namespace std;
//prototype
int NumberOfChar(string testCase);
int main()
{
    // declaration
    int N,  halfCharNum, halfTestCase, size;
    string testCase;
    // input
    cout<<"please enter an integer number, that will represent the number of test cases:      "<<endl;
//cin>>N;
    cout<< NumberOfChar(testCase)<<endl;
    halfCharNum=size/2;
    return 0;
}
int NumberOfChar(string testCase)
{
    cout << "Enter your string: " <<endl;
    getline(cin,testCase);
    const int size=testCase.length();
    cout << "The total number of characters entered is: "  << endl;
    return size;
}

这需要所有两行C++代码。

1) 反转

字符串 (标准::反转)

2)旋转字符串左n个字符,其中n是字符串中字符数的一半。(标准::旋转)

首先,将字符串中的每个元素替换为另一端的元素,然后逐步进入。

即在字符串"RP evol i gnimmargo"中,将第一个字符"r"与最后一个字符"o"交换,然后逐步进入,接下来将"P"与"g"交换,依此类推。

这让你留下了"我喜欢公关的表情"

然后,交换字符串的第一半和后半部分。

即"Ogramming I Love PR"可以分为"Ogramming"和"I Love PR"

- 只需将它们换成"I Love PR"和"Ogramming"并将它们组合在一起

只需使用大型英语单词词典并实现进化算法即可。可能不是通往荣耀的最短路径,但绝对是一项有趣的任务:-)

可以找到示例词典(您可能需要)

  • 这里
  • 这里
  • 或这里