题解 | 字符串最后一个单词的长度
#include <iostream> #include <string> #include <sstream> using namespace std; int main() { string line; getline(cin, line); stringstream ss(line); string str; int lastcount = 0; while (ss >> str) { // cout << str << ", len=" << str.length() << ", " ; if (str.length()) { lastcount = str.length(); } } cout << lastcount ; } // 64 位输出请用 printf("%lld")