-
-
Save hamadu/54d33c5123e59457b2e1f8d4c9d72125 to your computer and use it in GitHub Desktop.
io
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 characters
| #![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