描述 | |
---|---|
知识点 | 字符串,循环 |
运行时间限制 | 0M |
内存限制 | 0 |
输入 | 一行字符串,长度小于128。 |
输出 | 整数N,最后一个单词的长度。 |
样例输入 | hello world |
样例输出 | 5 |
#include<iostream>
#include<string>
using namespace std;
int main()
{
char str[128];
gets(str);
int count=0;
int len=strlen(str);
for(int i=(len-1);i>=0;i--)
{
if(str[i]!=' ')
{
count++;
}
else
{
break;
}
}
cout<<count<<endl;
system("pause");
return 0;
}