[华为机试练习题]19.字符串最后一个单词的长度
2015-06-30 15:11
211 查看
题目
![](http://img.blog.csdn.net/20150630151107068)
代码
代码
/*--------------------------------------- * 日期:2015-06-30 * 作者:SJF0115 * 题目:字符串最后一个单词的长度 * 来源:华为上机 -----------------------------------------*/ #include <iostream> #include <string> #include <algorithm> #include <vector> using namespace std; int LastWordLength(string str){ int size = str.size(); if(size == 0){ return 0; }//if // 去除后导0 int end = size - 1; while(end >= 0 && str[end] == ' '){ --end; }//while int len = 0; while(end >= 0 && str[end] != ' '){ ++len; --end; }//while return len; } int main(){ string str; //freopen("C:\\Users\\Administrator\\Desktop\\c++.txt","r",stdin); while(getline(cin,str)){ cout<<LastWordLength(str)<<endl; }//while return 0; }
相关文章推荐
- 安卓画日历控件2
- DM8168 debug continue... ...
- WPF的窗体设置WindowStyle=none时,如何移动窗体
- ARM嵌入式整理
- 积跬步,聚小流------java信息生成图片
- 安卓画日历控件
- win 8.1 64bit 深度学习theano 安装设置
- 应用笔划宽度变化(SWT)来检测自然场景中的文本
- RecyclerView的2种监听方式
- 关于中文处理方面的研究
- 安卓画日历控件
- python之SocketServer传文件实例
- 安卓画日历控件
- tomcat 配置server.xml 指定端口就可以直接打开项目。
- .NET4.5之初识async与await
- 让UIAlertController兼容的同时iphone和ipad
- 织梦dedecms|图片模型内容页标签
- PHP常用函数大全
- 安卓画日历控件
- 安卓画日历控件