Skip to content

Commit

Permalink
660
Browse files Browse the repository at this point in the history
  • Loading branch information
yamin8000 committed Sep 27, 2024
1 parent 84abd70 commit 588f55f
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 10 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This repo is a compilation of my submissions to [Quera.org](https://quera.org) q
| [Pythagoras_654.java](/src/main/java/Pythagoras_654.java) | [654](https://quera.org/problemset/654) | سه‌تایی فیثاغورثی | Java |
| [FarzadCinephile_655.java](/src/main/java/FarzadCinephile_655.java) | [655](https://quera.org/problemset/655) | فرزاد فیلم‌بین | Java |
| [FarzadWorkaholic_658.java](/src/main/java/FarzadWorkaholic_658.java) | [658](https://quera.org/problemset/658) | فرزاد کارکن | Java |
| [gifts_660.rs](/rust/main_cargo/src/gifts_660.rs) | [660](https://quera.org/problemset/660) | جشن هدیه‌ها | Rust |
| [Names_2529.kt](/src/main/kotlin/Names_2529.kt) | [2529](https://quera.org/problemset/2529) | اسم‌ها | Kotlin |
| [SumOfGreats_2551.kt](/src/main/kotlin/SumOfGreats_2551.kt) | [2551](https://quera.org/problemset/2551) | جمع بزرگان | Kotlin |
| [Chess_2636.go](/go/Chess_2636.go) | [2636](https://quera.org/problemset/2636) | شطرنج حرفه‌ای | Golang |
Expand Down
2 changes: 1 addition & 1 deletion rust/main_cargo/src/covid_178600.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ pub fn main() {
fn get_num() -> i32 {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap_or_default();
return input.trim().parse().unwrap_or_default();
input.trim().parse().unwrap_or_default()
}
6 changes: 3 additions & 3 deletions rust/main_cargo/src/factorization_298.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn main() {
fn get_num() -> i32 {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap_or_default();
return input.trim().parse().unwrap_or_default();
input.trim().parse().unwrap_or_default()
}

fn get_factors(mut n: i32) -> BTreeMap<i32, i32> {
Expand Down Expand Up @@ -57,7 +57,7 @@ fn get_factors(mut n: i32) -> BTreeMap<i32, i32> {
} else {
factors.insert(n, 1);
}
return factors;
factors
}

fn is_prime(n: i32) -> bool {
Expand All @@ -75,5 +75,5 @@ fn is_prime(n: i32) -> bool {
}
}
}
return true;
true
}
64 changes: 64 additions & 0 deletions rust/main_cargo/src/gifts_660.rs
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(&current) {
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
}
4 changes: 3 additions & 1 deletion rust/main_cargo/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod off_10327;
mod covid_178600;
mod factorization_298;
mod four_numbers_177663;
mod gifts_660;

fn main() {
//question_3408::question_3408();
Expand All @@ -14,5 +15,6 @@ fn main() {
//report_49535::main();
//off_10327::main();
//factorization_298::main();
four_numbers_177663::main();
//four_numbers_177663::main();
gifts_660::main();
}
4 changes: 2 additions & 2 deletions rust/main_cargo/src/off_10327.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ pub fn main() {
}
}

pub fn get_unique_chars(input: &str) -> Vec<char> {
fn get_unique_chars(input: &str) -> Vec<char> {
let mut uniques: Vec<char> = vec![];

for char in input.chars() {
if !uniques.contains(&char) {
uniques.push(char);
}
}
return uniques;
uniques
}
2 changes: 1 addition & 1 deletion rust/main_cargo/src/report_49535.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ pub fn main() {
fn get_num() -> i32 {
let mut input = String::new();
std::io::stdin().read_line(&mut input).unwrap();
return input.trim().parse().unwrap();
input.trim().parse().unwrap()
}
4 changes: 2 additions & 2 deletions rust/main_cargo/src/walnut_3540.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn main() {
}

fn steps(n: i32, x: i32, y: i32) -> (i32, i32) {
return if n % x == 0 {
if n % x == 0 {
(n / x, 0)
} else if n % y == 0 {
(0, n / y)
Expand All @@ -37,5 +37,5 @@ fn steps(n: i32, x: i32, y: i32) -> (i32, i32) {
}
}
} else { (-1, -1) }
};
}
}

0 comments on commit 588f55f

Please sign in to comment.