您的位置:首页 > 其它

字符串最后一个单词的长度-简单题

2015-08-28 00:00 183 查看
摘要: 输入:一行字符串,长度小于128
输出:整数N,最后一个单词的长度
得分:90

#include<iostream>
using namespace std;

int findLastNumLength(char *s,int le)
{
if(s==NULL||le<=0)
return 0;
int l=0;
char *endl=s;
while(*endl)
endl++;
endl--;
while(*endl==' ')
endl--;
while(le)
{
if(*endl!=' ')
{
l++;
endl--;
}
le--;
}
return l;
}

int main()
{
char s[100];
cin.getline(s,100);
cout<<findLastNumLength(s,strlen(s));
system("pause");
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: