-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_Kevin_and_Combination_Lock.rs
73 lines (69 loc) · 1.66 KB
/
A_Kevin_and_Combination_Lock.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#![allow(unused)]
fn solve(scan: &mut Scanner, case: usize) {
let mut n: usize = scan.next();
while let Some(idx) = n.to_string().find("33") {
if n % 33 == 0 {
break;
}
let mut s = n.to_string();
s.replace_range(idx..idx + 2, "");
n = s.parse().unwrap();
}
if n % 33 == 0 {
println!("YES");
return;
}
println!("NO");
}
fn main() {
let mut scan = Scanner::new();
let t: usize = 1;
let t: usize = scan.next();
(0..t).for_each(|case| solve(&mut scan, case + 1));
}
trait Print {
fn println(&self);
}
impl<T: std::fmt::Display> Print for T {
fn println(&self) {
println!("{}", self);
}
}
trait Prints {
fn println(&self);
}
impl<T: std::fmt::Display> Prints for Vec<T> {
fn println(&self) {
if let Some((last, elements)) = self.split_last() {
for element in elements {
print!("{} ", element);
}
println!("{}", last);
}
}
}
struct Scanner {
arr: Vec<String>,
}
impl Scanner {
fn new() -> Self {
Self { arr: Vec::new() }
}
fn next<T: std::str::FromStr>(&mut self) -> T
where
T::Err: std::fmt::Debug,
{
if self.arr.is_empty() {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
self.arr = input.split_whitespace().rev().map(String::from).collect();
}
self.arr.pop().unwrap().parse().unwrap()
}
fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T>
where
T::Err: std::fmt::Debug,
{
(0..n).map(|_| self.next()).collect()
}
}