#include <iostream>
#include <string.h>
using namespace std;
int main()
{
char ch[100];
gets(ch);
//getchar();
int len=strlen(ch);
int count=0;
int space=0;
for(int i=len-1;i>=0;i--)//倒序输出
{
cout<<ch[i];
}
cout<<endl;
for(int j=0;j<len;j++)//空格字符数统计
{
if(ch[j]==' ')
{
++space;
}
else
{
++count;
}
}
cout<<count<<endl;
cout<<space<<endl;
cout<<endl;;
return 0;
}
统计字符串字符空格数倒序输出C++
最新推荐文章于 2024-12-16 15:41:17 发布
本文介绍了一个使用C++实现的简单程序,该程序可以读取用户输入的字符串,然后逆序输出字符串,并统计字符串中非空格字符的数量。通过分析代码,读者可以了解如何使用C++标准库中的字符串函数,如strlen()和gets(),以及如何使用循环结构进行字符串遍历。
4455

被折叠的 条评论
为什么被折叠?



