Run ID:117309

提交时间:2025-04-16 20:30:32

#include <iostream> #include <string> using namespace std; int main() { string input; getline(cin, input); // 读取整行输入 string word; int length; int pos = 0; // 当前处理的位置 int n = input.length(); // 输入字符串的长度 while (pos < n) { // 跳过空格 while (pos < n && input[pos] == ' ') { ++pos; } // 如果已经到字符串末尾,结束循环 if (pos == n) break; // 找到单词的结尾 int start = pos; while (pos < n && input[pos] != ' ') { ++pos; } // 计算单词长度 length = pos - start; // 输出单词长度 cout << length; // 如果不是最后一个单词,输出逗号 if (pos < n) { cout << ","; } } return 0; }