Skip to content

Instantly share code, notes, and snippets.

@hamadu
Created May 26, 2017 00:03
Show Gist options
  • Select an option

  • Save hamadu/54d33c5123e59457b2e1f8d4c9d72125 to your computer and use it in GitHub Desktop.

Select an option

Save hamadu/54d33c5123e59457b2e1f8d4c9d72125 to your computer and use it in GitHub Desktop.
io
#![allow(unused)]
use std::io;
use std::collections::*;
use std::str::FromStr;
fn main() {
let a: Vec<i32> = read_tokens();
let b: Vec<String> = read_tokens();
println!("Hello, wo123rld! : {} / {}", a[0] + a[1] + a[2], b[1]);
let (x, y): (i32, String) = read_tuple2();
println!("ano : {} / {}", x, y);
}
fn read_line() -> String {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).expect("failed to read line");
buffer
}
fn read_i32() -> i32 {
read_line().trim().parse().unwrap_or_else(|e| panic!("{}", e))
}
fn read_tuple2<S:FromStr, T:FromStr>() -> (S, T) {
let v: Vec<String> = read_tokens();
return (
v[0].parse().unwrap_or_else(|e| panic!("ohmygod")),
v[1].parse().unwrap_or_else(|e| panic!("ohmygod"))
)
}
fn read_tuple3<S:FromStr, T:FromStr, U:FromStr>() -> (S, T, U) {
let v: Vec<String> = read_tokens();
return (
v[0].parse().unwrap_or_else(|e| panic!("ohmygod")),
v[1].parse().unwrap_or_else(|e| panic!("ohmygod")),
v[2].parse().unwrap_or_else(|e| panic!("ohmygod"))
)
}
fn read_tokens<T: std::str::FromStr>() -> Vec<T> {
let mut buffer = String::new();
io::stdin().read_line(&mut buffer).expect("failed to read line");
let mut buffer = buffer.split_whitespace();
let mut tokens = vec![];
loop {
match buffer.next() {
Some(token) => tokens.push(token.to_string().parse().unwrap_or_else(|e| panic!("ohmygod"))),
None => break
}
}
tokens
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment