Created
July 18, 2017 20:35
-
-
Save nothingnesses/6ad0e571d9ff52d4a27396b07eb35b27 to your computer and use it in GitHub Desktop.
Revisions
-
VoidNoire created this gist
Jul 18, 2017 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,43 @@ use std::io; fn main() { let mut v: Vec<f64> = Vec::new(); loop { let mut input = String::new(); io::stdin().read_line(&mut input) .expect("Failed to read line"); match input.trim() { "+" => { let (y,x) = (v.pop().unwrap(),v.pop().unwrap()); v.push(x+y); println!("{}", x+y); }, "-" => { let (y,x) = (v.pop().unwrap(),v.pop().unwrap()); v.push(x*y); println!("{}", x*y); }, "*" => { let (y,x) = (v.pop().unwrap(),v.pop().unwrap()); v.push(x*y); println!("{}", x*y); }, "/" => { let (y,x) = (v.pop().unwrap(),v.pop().unwrap()); v.push(x/y); println!("{}", x/y); }, "^" => { let (y,x) = (v.pop().unwrap(),v.pop().unwrap()); v.push(x.powf(y)); println!("{}", x.powf(y)); }, &_ => { v.push(input.trim().parse().unwrap()); }, } } }