题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
#include <iostream>
using namespace std;
int main() {
int a, b;
string str;
while (getline(cin,str)) { // 注意 这里不能用cin>>str,只能接收第一个空格前的字符串
string s = str.substr(str.rfind(' ')+1);//反转找第一个空格
cout<<s.size();
}
}
// 64 位输出请用 printf("%lld")
查看1道真题和解析
SHEIN希音公司福利 320人发布