Skip to content

Commit

Permalink
Merge pull request #439 from lunebakami/challenges/1-cubo-simples/rus…
Browse files Browse the repository at this point in the history
…t/lunebakami

Finalizando o desafio 1
  • Loading branch information
lanjoni authored Oct 13, 2023
2 parents 46258e4 + 36eb04e commit 37e03ff
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 0 deletions.
2 changes: 2 additions & 0 deletions challenges/1-cubo-simples/rust/lunebakami/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
.idea
7 changes: 7 additions & 0 deletions challenges/1-cubo-simples/rust/lunebakami/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions challenges/1-cubo-simples/rust/lunebakami/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "lunebakami"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
28 changes: 28 additions & 0 deletions challenges/1-cubo-simples/rust/lunebakami/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
* Modelo para submissão

Atenção! Siga o modelo abaixo em *markdown* para realizar o envio do =README.md= de cada um de seus exercícios.

#+BEGIN_SRC markdown
# Submissão de Exercicio

**Exercicio:** 1 - Cubo Simples

**Nickname:** lunebakami

**Nível Técnico:** - Pleno -

**Empresa:** - FCamara -

**Twitter**: https://twitter.com/lunebakami (opcional)

**Dificuldade de Resolução:** - Baixa -

**Comentários:** Nesse desafio eu achei que ... (Opcional)

**Como rodar o desafio**:

Use o comando abaixo:
```bash
cargo run
```
#+END_SRC
36 changes: 36 additions & 0 deletions challenges/1-cubo-simples/rust/lunebakami/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
fn main() {
let s = get_number();

if s < 0 {
println!("Número inválido!");

return;
}

let cube = s.pow(3);

println!("{}", cube);
}

fn get_number() -> isize {
use std::io::{stdin, stdout, Write};

let mut s = String::new();

println!("Por favor insira o número:");
let _ = stdout().flush();

stdin().read_line(&mut s).expect("Insira um texto válido!");

if let Some('\n') = s.chars().next_back() {
s.pop();
}

if let Some('\r') = s.chars().next_back() {
s.pop();
}

let number :isize = s.parse().unwrap_or(-1);

number
}

0 comments on commit 37e03ff

Please sign in to comment.