题解 | #字符串最后一个单词的长度#
字符串最后一个单词的长度
https://www.nowcoder.com/practice/8c949ea5f36f422594b306a2300315da
#include <iostream> #include <string> using namespace std; int main() { int a, b; string row; while (getline(cin, row)) { // 注意 while 处理多个 case int length = row.size(); string::size_type pos = row.find_last_of(' '); if (pos == string::npos) { cout << length << endl; } else { cout << length - pos - 1 << endl; } } return 0; } // 64 位输出请用 printf("%lld")#2023刷题记录#