尝试编写代码来更正由内而外编写的字符串句子
Trying to write a code the corrects a string sentence that is written inside out
我是一名软件工程专业的学生,我需要一些帮助来完成我被分配的作业我需要一个代码来纠正从内到外写的句子例;我喜欢编程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"并将它们组合在一起
只需使用大型英语单词词典并实现进化算法即可。可能不是通往荣耀的最短路径,但绝对是一项有趣的任务:-)
可以找到示例词典(您可能需要)
- 这里
- 这里
- 或这里
相关文章:
- 如何修复范围内的字符串声明错误
- 如何在数组中访问对象内的字符串
- 如何在 constexpr 函数内的字符串文字上静态断言条件
- C 在子字符串内找到字符串的最后一次出现
- 尝试编写代码来更正由内而外编写的字符串句子
- 在开关案例内将字符串化
- 向量内的字符串变量会导致大量错误(WinMainCRTStartup)
- 查找最外圆括号内的字符串
- 将无状态C++函数由内而外转换为有状态函数
- [C++]将一个字符串切成字符串,由另一个字符串中给出的符号以外的任何内容分隔
- C++ 中双引号内的字符串的数据类型是什么
- 由字符将字符串作为输入字符,并在按回车键时给出输出
- 如何将值应用于结构内的字符串变量
- 有没有更好(更有效)的方法来确定一个字符串是否可以由另一个字符串的字符组成
- 检查一个字符串是否可以由另一个字符串中的字符组成
- 如何打印由另一个字符串链表组成的链表
- 在小于0 (n)的时间内查找字符串中的字符
- 引号内的字符串
- 教授面向对象(c++)由外到内vs由内到外的方法
- 在短范围内验证字符串