Решение на упр.03 задача 1 от Милан Стойчев
Резултати
- 1 точка от тестове
- 0 бонус точки
- 1 точка общо
- 1 успешни тест(а)
- 0 неуспешни тест(а)
Код
 fn rainbow_replace(text: &str, word: &str, palette: &[char]) -> String {
    let max_count = palette.len();
    let mut count = 0;
    let n = word.chars().count();
    let mut res = String::from("");
     for w in text.split_whitespace() {
         if word == w {
             for i in 0..n {
                if count == max_count {
                    count = 0;
                }
                res.push(palette[count]);
                count = count + 1;
             }
         }
         else {
            res.push_str(w);
         }
         res.push(' ');
     }
     res.pop();
     return res;
 }
Лог от изпълнението
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-core v0.3.31
   Compiling futures-sink v0.3.31
   Compiling futures-channel v0.3.31
   Compiling memchr v2.7.6
   Compiling syn v2.0.108
   Compiling futures-task v0.3.31
   Compiling pin-project-lite v0.2.16
   Compiling pin-utils v0.1.0
   Compiling futures-io v0.3.31
   Compiling slab v0.4.11
   Compiling solution v0.1.0 (/tmp/d20251030-1757769-nhc1j8/solution)
warning: unused variable: `i`
 --> src/lib.rs:8:18
  |
8 |              for i in 0..n {
  |                  ^ help: if this is intentional, prefix it with an underscore: `_i`
  |
  = note: `#[warn(unused_variables)]` on by default
warning: function `rainbow_replace` is never used
 --> src/lib.rs:1:5
  |
1 |  fn rainbow_replace(text: &str, word: &str, palette: &[char]) -> String {
  |     ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default
warning: `solution` (lib) generated 2 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: `i`
 --> tests/../src/lib.rs:8:18
  |
8 |              for i in 0..n {
  |                  ^ help: if this is intentional, prefix it with an underscore: `_i`
  |
  = note: `#[warn(unused_variables)]` on by default
warning: `solution` (test "solution_test") generated 1 warning
    Finished `test` profile [unoptimized + debuginfo] target(s) in 8.50s
     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
История (2 версии и 0 коментара)
Милан качи решение на 23.10.2025 19:31 (преди 8 дена)
  fn rainbow_replace(text: &str, word: &str, palette: &[char]) -> String {
     let max_count = palette.len();
     let mut count = 0;
     let n = word.chars().count();
     let mut res = String::from("");
      for w in text.split_whitespace() {
          if word == w {
              for i in 0..n {
                 if count == max_count {
                     count = 0;
                 }
                 res.push(palette[count]);
                 count = count + 1;
              }
          }
          else {
             res.push_str(w);
          }
          res.push(' ');
      }
      res.pop();
      return res;
  }
- fn main() {
-     assert_eq!(
-         rainbow_replace("плодова салата", "плодова", &['🍆', '🍎', '🍒']),
-         "🍆🍎🍒🍆🍎🍒🍆 салата".to_string(),
-     );
- }
+
+
