题解 | 字符串最后一个单词的长度
#include <iostream> using namespace std; int main() { string _str; getline(cin, _str); string::reverse_iterator rit = _str.rbegin(); int count = 0; while(rit != _str.rend()) { if(*rit != ' ') { count++; rit++; } else { break; } } cout << count; }