如何将char阵列的中间单词更改为向后
How to change the middle word of a char array to backwards
我已经尝试过,但是我可以向后打印中间字!
ex。输入=这个词向后;输出=此滴水向后
char chai[80];
int cont=0;
cout << "Enter odd string words to reverse the one of the middle: ";
cin.getline(chai,80);
for(int x=0; x< strlen(chai) ;++x)
{
if(chai[x]==' ')
++cont;
}
任何建议都将受到赞赏,
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char chai[80];
cout<<"introduce your phrase with an odd number of words"<<endl;
cin.getline(chai,80);
int cont=0;
char c;
cout<<endl;
cout<<"Frase:"<<endl;
for(int x=0;x<=strlen(chai)-1;++x)//count the words
{
if(chai[x]==' ')
{
++cont;
cout<<chai[x];//spaces will help to find the word in the middle
}
else
cout<<chai[x];
}
cout<<endl;
cout<<endl;
if(cont%2!=0)
{
cout<<"It is necessary to introduce an odd number of words";
return 0;
}
cout<<endl;
cout<<endl;
int aux=cont/2;
int cont_dos=0;
int cont_tres=0;
cout<<"***It would be:***"<<endl;
for(int i=0;i<=strlen(chai)-1;++i)
{
if(chai[i]==' ')
{
cont_dos++;
if(cont_dos==aux)
{
for (int j=strlen(chai)-1;j!=0;--j)
{
if(chai[j]==' ')
{
cont_tres++;
cout<<chai[j];
}
if(cont_tres==aux)
{
cout<<chai[j];
++i;
if(cont_tres>aux)
{
++i;
cout<<chai[i];
if(i==strlen(chai)-1)
{
return 0;
}
}
}
//if(cont_tres>aux)
}
}
else
cout<<chai[i];
}
else
cout<<chai[i];
}
return 0;
}
相关文章:
- 文本文件中的单词链表
- 2D数组来自文本输入,中间有空格
- C++:将控制台输出存储在宏中更好吗
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 当在带有Eigen的C++中使用GDB时,我如何才能看到更多的大矩阵
- FFmpeg:制作一个应用程序比直接使用ffmepg更好吗
- 在指针的帮助下,文本文件中单词的频率
- 为什么在浮点中从大到小会引入更多的误差
- 如何将更多文件夹添加到c++include路径
- 模板的模板的模板推演失败(中间有继承),有没有更好的方法.
- 如何使我的单词查找更清晰、更高效
- 如何将char阵列的中间单词更改为向后
- 在Java中使用一个或更多单词搜索整个数据库
- 将中间变量用于三元运算符(或类似运算符)以获得更好的性能
- 当没有更多的单词时,如何使用>>停止阅读
- 把一个单词分成更小的部分
- 通过修改二叉搜索算法来改进它,使其在搜索大量单词(单词列表)中的单词时工作得更快
- 我编写了一个C++程序来打印单词字母的排列.我想知道是否有其他更简单的方法可以做到这一点
- 在 C++ 的文本文件中添加更多单词
- 算法:计算单词列表频率的更好方法