-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgifts_660.rs
64 lines (55 loc) · 1.81 KB
/
gifts_660.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
use std::collections::HashMap;
pub fn main() {
let n: i16 = read_input().trim().parse().unwrap_or_default();
let mut people: HashMap<String, i16> = HashMap::new();
let mut orders: Vec<String> = Vec::new();
for index in 0..n {
let person = read_input().trim().to_string();
people.insert(person.clone(), 0);
orders.insert(index as usize, person)
}
for _i in 0..n {
let current = read_input().trim().to_string();
let gifts: Vec<i16> = read_input().trim().to_string().split_whitespace()
.map(|x| x.parse().unwrap_or_default())
.collect();
let total_money = match gifts.first() {
None => { 0 }
Some(x) => *{ x }
};
let receivers = match gifts.last() {
None => { 0 }
Some(x) => *{ x }
};
if receivers != 0 {
for _i in 0..receivers.clone() {
match people.get_mut(¤t) {
None => {}
Some(current_person) => {
*current_person -= total_money / receivers;
}
}
let gifted = read_input().trim().to_string();
match people.get_mut(&gifted) {
None => {}
Some(gifted_person) => {
*gifted_person += total_money / receivers;
}
}
}
}
}
for order in orders {
match people.iter().find(|x| *x.clone().0 == order) {
None => {}
Some(person) => {
println!("{} {}", person.0, person.1)
}
}
}
}
fn read_input() -> String {
let mut temp = String::new();
std::io::stdin().read_line(&mut temp).unwrap_or_default();
temp
}