题目描述
输入一行字符串(字符个数不超过80),统计出该字符串的长度和字符串中出现的空格个数。
在下面代码的基础上完成,提交时只提交begin所在行和end所在行之间的代码。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
//—–begin——-
//—–end——–
return 0;
}
输入
一行字符串(字符个数不超过80)
输出
输出两行,第一行输出字符串长度(注意不包括'\0'),第二行输出空格个数。
样例输入
I love China!
样例输出
13
2
参考代码
#include<stdio.h>
#include<string.h>
int main()
{
char a[100];
gets(a);
char p;
int count=0;
int i,m=strlen(a);
for (i=0; i<m; i++)
{
if(a[i]==' ')
count++;
}
printf("%dn",m);
printf("%dn",count);
return 0;
}
解析
暂无