-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
77 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters