Rust: Grab standard input on HackerRank
Date: 2018-10-24 |
Problem: I'm trying to do a Rustlang problem on HackerRank but can't figure out how to read in the input (provided via stdin), how do I do this?
Solution: Use the std::io crate!
Here's an example:
Or, if the embed's not working, the current state (as of writeTime):
use std::io;
fn main() {
// Create a mutable String read_line can "read" into
let mut input = String::new();
// Read the stdin into our input variable
io::stdin().read_line(&mut input).expect("something went wrong");
// Many HackerRank inputs come in delimited by spaces, this is how you might
// make that usable
let iterable_input = input.split(" ");
}
Want more like this?
The best / easiest way to support my work is by subscribing for future updates and sharing with your network.