Git Product home page Git Product logo

fast_input's Introduction

Rust

FastInput - Read input, fast!

FastInput is aimed to simplify reading of known input from stdin, mainly in a competetive programming environment. The crate exposes the FastInput struct which contains methods for reading and parsing line-based input. FastInput does no validation of the input and uses unsafe operations and buffering to achieve great performance.

Example

The following example creates a new FastInput and reads some input:

use fast_input::{FastInput, Str};

let input = FastInput::new();
let first_line = input.next_line();

// Type arguments can often be omitted as rust is awesome,
// specified here for clarity.
let (a, b): (u32, u32) = input.next_tuple();

println!("First line was: {}, a + b = {}", first_line, a + b);

// Read a line of integers and collect into a `Vec`
let numbers: Vec<u32> = input.next_as_iter().collect();

// `FastInput` contains methods to read up to quintuples
let (a, b, c, d, e) = input.next_quintuple();
let sum: i32 = 0i32 + a + b + c + d + e;


// The `Str` type can be used to mix string slices with parsed data
let (name, age) = input.next_tuple::<Str, u8>();
// `Str` can be dereferenced into its contained string slice
let name: &str = *name;

// Read all remaining lines and print them
for line in input.lines() {
    println!("{}", line);
}

fast_input's People

Contributors

klasafgeijerstam avatar kubajagiello avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.