Skip to content

Instantly share code, notes, and snippets.

@segfo
Created April 15, 2020 00:54
Show Gist options
  • Save segfo/502357e4261b4eaa2e23ef2b5a763cd7 to your computer and use it in GitHub Desktop.
Save segfo/502357e4261b4eaa2e23ef2b5a763cd7 to your computer and use it in GitHub Desktop.
AtCoder入力マクロ
use std::io::BufRead;
macro_rules! readlines {
($cnt:expr) => {
{
let stdin = std::io::stdin();
let mut handle = stdin.lock();
let mut result = Vec::new();
for i in 0..$cnt{
let mut buf = String::new();
handle.read_line(&mut buf);
result.push(buf.trim().to_owned());
}
result
}
};
}
macro_rules! string2splittedvec {
($t:ty,$sep:expr,$line:expr) => {
{
$line.split($sep)
.map(|s|s.parse::<$t>().unwrap())
.collect::<Vec<_>>()
}
};
($t:ty,$line:expr) => {
{
string2splittedvec!($t,' ',$line)
}
};
($sep:expr,$line:expr) => {
{
$line.split($sep)
.map(|s|s.to_owned())
.collect::<Vec<_>>()
}
};
($line:expr)=>{
{
string2splittedvec!(' ',$line)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment