Skip to content

Commit

Permalink
Add atcoder/abc354/a.rs atcoder/abc354/b.rs atcoder/abc354/remain.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
koba-e964 committed Jun 27, 2024
1 parent e307290 commit 2a2be29
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
35 changes: 35 additions & 0 deletions atcoder/abc354/a.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use std::io::Read;

fn get_word() -> String {
let stdin = std::io::stdin();
let mut stdin=stdin.lock();
let mut u8b: [u8; 1] = [0];
loop {
let mut buf: Vec<u8> = Vec::with_capacity(16);
loop {
let res = stdin.read(&mut u8b);
if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
break;
} else {
buf.push(u8b[0]);
}
}
if buf.len() >= 1 {
let ret = String::from_utf8(buf).unwrap();
return ret;
}
}
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn main() {
let h: i64 = get();
let mut x = 0;
let mut y = 0;
while x <= h {
x += 1 << y;
y += 1;
}
println!("{}", y);
}
42 changes: 42 additions & 0 deletions atcoder/abc354/b.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
($($r:tt)*) => {
let stdin = std::io::stdin();
let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
let mut next = move || -> String{
bytes.by_ref().map(|r|r.unwrap() as char)
.skip_while(|c|c.is_whitespace())
.take_while(|c|!c.is_whitespace())
.collect()
};
input_inner!{next, $($r)*}
};
}

macro_rules! input_inner {
($next:expr) => {};
($next:expr,) => {};
($next:expr, $var:ident : $t:tt $($r:tt)*) => {
let $var = read_value!($next, $t);
input_inner!{$next $($r)*}
};
}

macro_rules! read_value {
($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) };
($next:expr, [ $t:tt ; $len:expr ]) => {
(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
};
($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

fn main() {
input! {
n: usize,
sc: [(String, usize); n],
}
let mut sc = sc;
sc.sort();
let tot: usize = sc.iter().map(|&(_, c)| c).sum();
println!("{}", sc[tot % n].0);
}
5 changes: 5 additions & 0 deletions atcoder/abc354/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
c
d
e
f
g

0 comments on commit 2a2be29

Please sign in to comment.