#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[129];
int n;
int len;
while(cin.getline(str,128))
{
n=0;
len=strlen(str)-1;
while(str[len]!=' '&&len>=0)
{
n++;
len--;
}
cout<<n<<endl;
}
return 0;
}
/*
int main()
{
string str;
int n;
int len;
while(getline(cin,str))
{
n=0;
len=str.size();
while(str[--len]!=' ')
n++;
cout<<n<<endl;
}
return 0;
}
*/华为oj_字符串最后一个单词的长度
最新推荐文章于 2025-10-25 20:01:49 发布
本文介绍了一个使用C++实现的简单程序,该程序能够读取一行文本,并统计该行文本末尾连续空格的数量。通过两种不同的方法实现了这一功能:一种使用了字符数组,另一种使用了C++标准库中的string类型。这些示例展示了如何利用C++的输入输出流和字符串处理技巧。

128

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



