题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
//C++
#include <iostream>
#include <string>using namespace std;
int main(){
string s;
getline(cin,s);
int num = 0;
for(int i = s.length()-1; i >= 0; i--){
if(s[i] != ' '){
num++;
}
else{
break;
}
}
cout << num;
}