题解 | 字符串最后一个单词的长度
#include <iostream> #include <string> using namespace std; int main() { string a, b; while (cin >> b) { a += b; a += " "; } a.pop_back(); int index = a.find_last_of(' '); string c = a.substr(index+1, a.length()-index-1); cout << c.length(); } // 64 位输出请用 printf("%lld")