Skip to content

Commit 1856e68

Browse files
committed
add 15, 17 & 20
- 15 -- string reverse - 17 -- word count - 20 -- BMI calculator
1 parent 26d6bf0 commit 1856e68

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

src/15-reverse.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let string: &'static str = "The quick brown fox jumps over the lazy dog";
3+
let reverse: String = string.chars().rev().collect();
4+
println!(" normal = `{}`", string);
5+
println!("reversed = `{}`", reverse);
6+
}

src/17-words.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
let string: &'static str = "The quick brown fox jumps over the lazy dog";
3+
let word_count = string.split(' ').collect::<Vec<_>>().len();
4+
println!("string = `{}`", string);
5+
println!(" count = {}", word_count);
6+
}

src/20-bmi.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use std::io;
2+
3+
fn main() {
4+
let mut buffer = String::new();
5+
println!("Введите массу тела, кг");
6+
io::stdin().read_line(&mut buffer).unwrap();
7+
let mass = match buffer.trim().parse::<f32>() {
8+
Ok(value) => value,
9+
Err(error) => panic!("{}", error),
10+
};
11+
buffer.clear();
12+
println!("Введите рост, м");
13+
io::stdin().read_line(&mut buffer).unwrap();
14+
let height = match buffer.trim().parse::<f32>() {
15+
Ok(value) => value,
16+
Err(error) => panic!("{}", error),
17+
};
18+
let BMI = mass / height.powi(2);
19+
println!("Индекс массы тела равен {}", BMI);
20+
let status = if BMI > 0.0 && BMI < 16.0 {
21+
"Выраженный дефицит массы тела".to_owned()
22+
} else if BMI >= 16.0 && BMI < 18.5 {
23+
"Недостаточная (дефицит) масса тела".to_owned()
24+
} else if BMI >= 18.5 && BMI <= 24.99 {
25+
"Норма".to_owned()
26+
} else if BMI >= 25.0 && BMI < 30.0 {
27+
"Избыточная масса тела (предожирение)".to_owned()
28+
} else if BMI >= 30.0 && BMI < 35.0 {
29+
"Ожирение первой степени".to_owned()
30+
} else if BMI >= 35.0 && BMI < 40.0 {
31+
"Ожирение второй степени".to_owned()
32+
} else {
33+
"Ожирение третьей степени (морбидное)".to_owned()
34+
};
35+
println!("Статус: {}", status);
36+
}

0 commit comments

Comments
 (0)