tinycodinglm / cp2 /cp-0021.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 15)
b27bfb3 verified
|
Raw History Blame Contribute Delete
2.56 kB
cp-practice-sim trace
System 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.

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.

User 2026-11-07T18:20:03.537Z

Word Count and Longest

Topic: String manipulation and parsing | Difficulty: beginner

Problem

A 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.

Input

A single line of text containing at least one word.

Output

Print two integers separated by a space: the number of words and the maximum word length.

Constraints

  • 1 <= line length <= 2*10^5
  • the line contains lowercase letters and spaces only, with at least one letter

Examples

Example 1

Input:

markdown
hello   big world

Output:

markdown
3 5

Example 2

Input:

markdown
x

Output:

markdown
1 1

Solve this in C++17, Rust, Kotlin, one complete program per language. Code only, no explanation.

Assistant 2026-11-07T18:20:05.511Z

C++17

cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
    string w;
    int cnt = 0;
    size_t best = 0;
    while (cin >> w) {
        cnt++;
        best = max(best, w.size());
    }
    printf("%d %zu\n", cnt, best);
}

Rust

rust
use std::io::*;
fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut cnt = 0;
    let mut best = 0;
    for w in s.split_whitespace() {
        cnt += 1;
        best = best.max(w.len());
    }
    println!("{} {}", cnt, best);
}

Kotlin

kotlin
fun main() {
    val words = System.`in`.bufferedReader().readText().split(Regex("\\s+")).filter { it.isNotEmpty() }
    println("${words.size} ${words.maxOf { it.length }}")
}