Решение на упр.06 задача 1 от Георги Георгиев

Обратно към всички решения

Към профила на Георги Георгиев

Резултати

  • 4 точки от тестове
  • 0 бонус точки
  • 4 точки общо
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)

Код

pub struct ImportantExcerpt<'a> {
pub part: &'a str,
}
impl<'a> ImportantExcerpt<'a> {
pub fn level(&self) -> i32 {
3
}
pub fn announce_and_return_part(&self, announcement: &str) -> &str {
println!("Anouncement: {}", announcement);
self.part
}
}
pub fn first_or_default<'a>(text1: &'a str, text2: &'a str, threshold: usize) -> &'a str {
if text1.len() >= threshold {
text1
} else {
text2
}
}
pub fn first_word<'a>(s: &'a str) -> &'a str {
s.split_once(' ').map_or(s,|(first, _all)| first)
}
pub fn find_longest_excerpt<'a>(excerpts: &'a [ImportantExcerpt]) -> Option<&'a str> {
let mut res : Option<&'a str> = None;
for e in excerpts{
match res {
Some(cur) if cur.len() >= e.part.len()=>{} _=> res = Some(e.part),
}
}
res
}

Лог от изпълнението

Compiling solution v0.1.0 (/tmp/d20261119-2321049-n6jmp1/solution)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.36s
     Running unittests src/lib.rs (target/debug/deps/solution-2e550d2f70dd933d)

running 4 tests
test solution_test::test_find_longest ... ok
test solution_test::test_find_longest_2 ... ok
test solution_test::test_first_or_default ... ok
test solution_test::test_first_word ... ok

test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

История (1 версия и 0 коментара)

Георги качи първо решение на 14.11.2026 14:35 (преди 17 дена)