华为机试——字符串最后一个单词长度
2016-01-08 15:25
183 查看
题目:计算字符串最后一个单词的长度,单词以空格隔开
#include<iostream> #include<string> #include<algorithm> using namespace std; int main() { string str,lastword; getline(cin,str); string::size_type pos,end=str.size()-1; pos=str.rfind(" ",end); if(pos!=0) { lastword=str.substr(pos+1,end-pos); cout<<lastword.size(); } else return -1; }
相关文章推荐
- crtmpserver 在VS2010下的build
- 图像分析之图像锐化
- 你知道数据库索引的工作原理吗?
- sqlzoo练习答案--SELECT names/zh
- thrift 基于window的安装配置
- SQL Server 2016 COMPRESS 和 DECOMPRESS 函数
- xampp+yii2环境搭建
- iOS(四)动漫App:二
- Fast RCNN 训练自己的数据集(3训练和检测)
- CDI技术第九步 构造注入与setter注入
- 简单说说Android自定义view学习推荐的方式
- 3.5.13其它函数
- 简单说说Android自定义view学习推荐的方式
- 前端开发疑难杂症篇(一)
- Codeforces Round #336 Marbles
- Mysql一些常用语句
- Handler3
- linux系统启动流程
- 2.java成长之路——重读java编程思想02
- 关于扩展 Laravel 默认 Session 中间件导致的 Session 写入失效问题分析