{"type": "session", "harness": "cp-practice-sim", "id": "cp-0021", "name": "Word Count and Longest", "mode": "chat", "topic": "String manipulation and parsing", "difficulty": "beginner", "tags": ["strings", "parsing", "tokens"], "explanation_mode": "none", "tool_scenario": "none", "expected_recovery": "N/A - no fault injected.", "languages": ["cpp", "rust", "kotlin"], "unexecuted_languages": [], "time_complexity": "O(n)", "space_complexity": "O(n)"} {"type": "message", "message": {"role": "system", "content": "You are a competitive-programming assistant. Deliver correct, complete, runnable solutions that read standard input and write standard output. Reply with code only; no explanation. ", "timestamp": 1794075601700}} {"type": "message", "message": {"role": "user", "content": "# Word Count and Longest\n\nTopic: String manipulation and parsing | Difficulty: beginner\n\n## Problem\nA line of text consists of lowercase words separated by one or more spaces; there may be leading and trailing spaces. Print the number of words and the length of the longest word.\n\n## Input\nA single line of text containing at least one word.\n\n## Output\nPrint two integers separated by a space: the number of words and the maximum word length.\n\n## Constraints\n- 1 <= line length <= 2*10^5\n- the line contains lowercase letters and spaces only, with at least one letter\n\n## Examples\n### Example 1\nInput:\n```\n hello big world \n```\nOutput:\n```\n3 5\n```\n\n### Example 2\nInput:\n```\nx\n```\nOutput:\n```\n1 1\n```\n\nSolve this in C++17, Rust, Kotlin, one complete program per language. Code only, no explanation.", "timestamp": 1794075603537}} {"type": "message", "message": {"role": "assistant", "content": "### C++17\n```cpp\n#include \nusing namespace std;\nint main() {\n string w;\n int cnt = 0;\n size_t best = 0;\n while (cin >> w) {\n cnt++;\n best = max(best, w.size());\n }\n printf(\"%d %zu\\n\", cnt, best);\n}\n```\n\n### Rust\n```rust\nuse std::io::*;\nfn main() {\n let mut s = String::new();\n stdin().read_to_string(&mut s).unwrap();\n let mut cnt = 0;\n let mut best = 0;\n for w in s.split_whitespace() {\n cnt += 1;\n best = best.max(w.len());\n }\n println!(\"{} {}\", cnt, best);\n}\n```\n\n### Kotlin\n```kotlin\nfun main() {\n val words = System.`in`.bufferedReader().readText().split(Regex(\"\\\\s+\")).filter { it.isNotEmpty() }\n println(\"${words.size} ${words.maxOf { it.length }}\")\n}\n```", "timestamp": 1794075605511}}