分类:字符串处理
关键字:字符串、空格、末尾‘,’输出处理
截图如下:
题目要求:
代码如下:
#include<iostream>
#include<stdio.h>
#include<string.h>
using std::cout;
//using namespace std; //以上三行可以用using namespace std;代替
int main()
{
char s[1001];
gets(s);
int i = strlen(s);
int q = i;
int c = 0;
for( ; i>0; i--)
{
if(s[q - i] == ' ')
{
cout<<c<<',';
c = 0;
}
else if(i == 1)
{
cout<<++c;
break;
}
else
c++;
}
return 0;
}