您的位置:首页 > 其它

【华为oj2290】字符串最后一个单词的长度

2014-07-01 09:44 323 查看
如 hello world

5
#include<iostream>
#include<string>

using namespace std;

int main()
{
	string input ("abcd");
	string output ("bcd");
	string::size_type pos = 0;
	string::size_type length = 0;
	
	getline (cin,input);//  输入字符串

	//查找最后一个空格,空格的下一位就是单词的开始

	pos = input.find_last_of (" ");
	output = input.substr (pos + 1);//输出最后一个空格到最后的子串

	length = output.size();
	cout << length << endl;
    system("pause");
    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: