-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathdetective-geek.rs
More file actions
29 lines (23 loc) · 933 Bytes
/
detective-geek.rs
File metadata and controls
29 lines (23 loc) · 933 Bytes
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
use std::io;
fn read_string() -> String {
let mut input_line = String::new();
io::stdin().read_line(&mut input_line).unwrap();
input_line.trim_matches('\n').to_string()
}
fn main() {
let months = ["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"];
let time = read_string().chars().map(|c| {
match c {
'#' => 1,
_ => 0,
}
}).fold(0, |acc, x| 2 * acc + x);
let mut addr = String::new();
for word in read_string().split_whitespace() {
let (a, b) = word.split_at(word.len() / 2);
addr.push(char::from(u8::from_str_radix(format!("{}{}",
char::from_digit(months.iter().position(|&x| x == a).unwrap() as u32, 12).unwrap(),
char::from_digit(months.iter().position(|&x| x == b).unwrap() as u32, 12).unwrap()).as_str(), 12).unwrap()));
};
println!("{:02}:{:02}\n{}", time/100, time % 100, addr);
}