Calculate the last word's length
/* Function : calculate the last word's length.I wrote again for this question because I think the former solution is too bad... Author : Diamond Time : 2015/06/06 20:58:00.000 */ #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> using namespace std; int main() { string str; getline(cin,str); int len=str.length(); for(int i=len-1;i>=0;i--) { if(str[i]==' ') { cout<<len-i-1; break; } } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
posted on 2015-06-06 21:06 Tob__yuhong 阅读(128) 评论(0) 编辑 收藏 举报