angrycder's blog

By angrycder, history, 16 months ago, In English

Rust is a viable programming language to compete in competitive programming but one of the difficulty that beginners (in rust) face is taking line input . I have added line input functions with templates. Hope it helps you.

use std::io;
use std::str::FromStr;

fn read_line() -> String {
    let mut buffer = String::new();
        .read_line(&mut buffer)
        .expect("failed to read line");

fn read<T : FromStr>() -> Result<T, T::Err>{

fn read_vec<T : FromStr>() -> Result< Vec<T>, T::Err>{
    read_line().split_whitespace().map(|x| x.parse::<T>()).collect()

fn solve(){


fn main() {
    let t = read::<i32>().unwrap();
    for _i in 0..t {
  • Vote: I like it
  • 0
  • Vote: I do not like it