统计字符串字符空格数C++

#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;2
	for(int j=0;j<len;j++)
	{
		if(ch[j]==' ')
		{
			++space;
		}
		else
		{
			++count;
		}
	}
	cout<<count<<endl;
	cout<<space<<endl;
	cout<<endl;;
	return 0;

}

猜你喜欢

转载自blog.csdn.net/qq_37181805/article/details/88420163