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

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

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

Резултати

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

Код

fn rainbow_replace(text: &str, word: &str, palette: &[char]) -> String {
if word.is_empty() || palette.is_empty()
{
return text.to_string();
}
let textVec: Vec<char> = text.chars().collect();
let wordVec: Vec<char> = word.chars().collect();
let mut result = String::new();
let mut paletteCounter = 0;
let mut i = 0;
while i < textVec.len()
{
if i + wordVec.len() <= textVec.len() && textVec[i..i + wordVec.len()] == wordVec[..]
{
for z in wordVec.iter() {
result.push(palette[paletteCounter % palette.len()]);
paletteCounter = paletteCounter+1;
}
i = i + wordVec.len();
}
else
{
result.push(textVec[i]);
i = i+ 1;
}
}
result
}

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

Updating crates.io index
     Locking 17 packages to latest compatible versions
   Compiling proc-macro2 v1.0.103
   Compiling unicode-ident v1.0.22
   Compiling quote v1.0.41
   Compiling futures-sink v0.3.31
   Compiling futures-core v0.3.31
   Compiling futures-channel v0.3.31
   Compiling futures-io v0.3.31
   Compiling pin-project-lite v0.2.16
   Compiling syn v2.0.108
   Compiling pin-utils v0.1.0
   Compiling slab v0.4.11
   Compiling futures-task v0.3.31
   Compiling memchr v2.7.6
   Compiling solution v0.1.0 (/tmp/d20251030-1757769-1iujsf0/solution)
warning: unused variable: `z`
  --> src/lib.rs:19:17
   |
19 |             for z in wordVec.iter() {
   |                 ^ help: if this is intentional, prefix it with an underscore: `_z`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: function `rainbow_replace` is never used
 --> src/lib.rs:1:4
  |
1 | fn rainbow_replace(text: &str, word: &str, palette: &[char]) -> String {
  |    ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: variable `textVec` should have a snake case name
 --> src/lib.rs:7:9
  |
7 |     let textVec: Vec<char> = text.chars().collect();
  |         ^^^^^^^ help: convert the identifier to snake case: `text_vec`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: variable `wordVec` should have a snake case name
 --> src/lib.rs:8:9
  |
8 |     let wordVec: Vec<char> = word.chars().collect();
  |         ^^^^^^^ help: convert the identifier to snake case: `word_vec`

warning: variable `paletteCounter` should have a snake case name
  --> src/lib.rs:11:13
   |
11 |     let mut paletteCounter = 0;
   |             ^^^^^^^^^^^^^^ help: convert the identifier to snake case: `palette_counter`

warning: `solution` (lib) generated 5 warnings
   Compiling futures-macro v0.3.31
   Compiling futures-util v0.3.31
   Compiling futures-executor v0.3.31
   Compiling futures v0.3.31
warning: unused variable: `z`
  --> tests/../src/lib.rs:19:17
   |
19 |             for z in wordVec.iter() {
   |                 ^ help: if this is intentional, prefix it with an underscore: `_z`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: variable `textVec` should have a snake case name
 --> tests/../src/lib.rs:7:9
  |
7 |     let textVec: Vec<char> = text.chars().collect();
  |         ^^^^^^^ help: convert the identifier to snake case: `text_vec`
  |
  = note: `#[warn(non_snake_case)]` on by default

warning: variable `wordVec` should have a snake case name
 --> tests/../src/lib.rs:8:9
  |
8 |     let wordVec: Vec<char> = word.chars().collect();
  |         ^^^^^^^ help: convert the identifier to snake case: `word_vec`

warning: variable `paletteCounter` should have a snake case name
  --> tests/../src/lib.rs:11:13
   |
11 |     let mut paletteCounter = 0;
   |             ^^^^^^^^^^^^^^ help: convert the identifier to snake case: `palette_counter`

warning: `solution` (test "solution_test") generated 4 warnings
    Finished `test` profile [unoptimized + debuginfo] target(s) in 8.38s
     Running tests/solution_test.rs (target/debug/deps/solution_test-bfd50394249726db)

running 1 test
test solution_test::test_basic ... ok

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

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

Йоан качи първо решение на 29.10.2025 20:34 (преди 1 ден)