-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #439 from lunebakami/challenges/1-cubo-simples/rus…
…t/lunebakami Finalizando o desafio 1
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
.idea |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |