chore(rs): create a template and adjust gitignore

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2023-07-23 21:23:45 +02:00
parent f333cf115a
commit bbe76f33d6
Signed by: mfocko
GPG key ID: 7C47D46246790496
7 changed files with 147 additions and 1 deletions

1
.common/rust/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

7
.common/rust/Cargo.lock generated Normal file
View file

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "Codeforces"
version = "0.1.0"

8
.common/rust/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "Codeforces"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

7
.common/rust/init.sh Normal file
View file

@ -0,0 +1,7 @@
#!/bin/sh
for TASK in a b c d e f g h;
do
cp src/main.rs src/bin/$TASK.rs;
done;

View file

119
.common/rust/src/main.rs Normal file
View file

@ -0,0 +1,119 @@
use self::math::*;
use self::output::*;
use self::input::*;
fn solve(s: &mut Scanner) {
todo!()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn example_1() {
assert_eq!(1, 2);
}
}
// region runner
const SINGLE_TEST: bool = false;
fn main() {
let mut s = Scanner::new();
if SINGLE_TEST {
solve(&mut s)
} else {
let N = s.next::<i32>();
for _ in 0..N {
solve(&mut s)
}
}
}
// endregion runner
mod math {
const MOD: i64 = 1_000_000_007;
pub fn add(a: i64, b: i64) -> i64 {
(a + b) % MOD
}
pub fn sub(a: i64, b: i64) -> i64 {
((a - b) % MOD + MOD) % MOD
}
pub fn mul(a: i64, b: i64) -> i64 {
(a * b) % MOD
}
pub fn exp(b: i64, e: i64) -> i64 {
if e == 0 {
return 1;
}
let half = exp(b, e / 2);
if e % 2 == 0 {
return mul(half, half);
}
return mul(half, mul(half, b));
}
}
mod output {
pub fn yes() {
println!("YES");
}
pub fn no() {
println!("NO");
}
pub fn yesno(ans: bool) {
println!("{}", if ans { "YES" } else { "NO" });
}
}
mod input {
use std::collections::VecDeque;
use std::io;
use std::str::FromStr;
pub struct Scanner {
buffer: VecDeque<String>,
}
impl Scanner {
pub fn new() -> Scanner {
Scanner {
buffer: VecDeque::new(),
}
}
pub fn next<T: FromStr>(&mut self) -> T {
if self.buffer.len() == 0 {
let mut input = String::new();
io::stdin().read_line(&mut input).ok();
for word in input.split_whitespace() {
self.buffer.push_back(word.to_string())
}
}
let front = self.buffer.pop_front().unwrap();
front.parse::<T>().ok().unwrap()
}
pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
let mut arr = vec![];
for _ in 0..n {
arr.push(self.next::<T>());
}
arr
}
}
}

4
.gitignore vendored
View file

@ -23,6 +23,10 @@
# Kotlin # Kotlin
!*.kt !*.kt
# Rust
!.common/rust/**
!*.rs
# Don't ignore skeletons in .common, but do all others # Don't ignore skeletons in .common, but do all others
**/skeleton* **/skeleton*
!.common/**/skeleton* !.common/**/skeleton*