From 387cbcb94cdcb7b663e2aff79b7b7a50798bd3fa Mon Sep 17 00:00:00 2001 From: Muhammad Nauman Raza Date: Sun, 9 Feb 2025 13:19:50 +0000 Subject: [PATCH] cargo: fmt --- solutions/rust/src/bin/116A.rs | 7 +++++-- solutions/rust/src/bin/1327A.rs | 9 ++++++--- solutions/rust/src/bin/149A.rs | 9 ++++++--- solutions/rust/src/bin/1807A.rs | 4 ++-- solutions/rust/src/bin/1968A.rs | 4 ++-- solutions/rust/src/bin/200B.rs | 5 ++++- solutions/rust/src/bin/2044B.rs | 4 ++-- solutions/rust/src/bin/236A.rs | 2 +- solutions/rust/src/bin/25A.rs | 9 ++++++--- solutions/rust/src/bin/313A.rs | 10 +++++++--- solutions/rust/src/bin/318A.rs | 13 ++++++++----- solutions/rust/src/bin/337A.rs | 19 ++++++++++++------- solutions/rust/src/bin/339A.rs | 6 +++++- solutions/rust/src/bin/34B.rs | 20 ++++++++++++++------ solutions/rust/src/bin/405A.rs | 10 ++++++++-- solutions/rust/src/bin/451A.rs | 11 +++++++---- solutions/rust/src/bin/466A.rs | 20 ++++++++++++-------- solutions/rust/src/bin/580A.rs | 9 ++++++--- solutions/rust/src/bin/598A.rs | 3 +-- solutions/rust/src/bin/617A.rs | 2 +- solutions/rust/src/bin/705A.rs | 2 +- solutions/rust/src/bin/791A.rs | 5 ++++- 22 files changed, 120 insertions(+), 63 deletions(-) diff --git a/solutions/rust/src/bin/116A.rs b/solutions/rust/src/bin/116A.rs index dd4e754..b95cced 100644 --- a/solutions/rust/src/bin/116A.rs +++ b/solutions/rust/src/bin/116A.rs @@ -11,9 +11,12 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let s: Vec = s.split_whitespace().map(|d| d.parse::().unwrap()).collect(); + let s: Vec = s + .split_whitespace() + .map(|d| d.parse::().unwrap()) + .collect(); - people += s[1]-s[0]; + people += s[1] - s[0]; if people > maximum { maximum = people; diff --git a/solutions/rust/src/bin/1327A.rs b/solutions/rust/src/bin/1327A.rs index 603c609..0c59f3b 100644 --- a/solutions/rust/src/bin/1327A.rs +++ b/solutions/rust/src/bin/1327A.rs @@ -9,9 +9,12 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let a: Vec = s.split_whitespace().map(|d| d.parse::().unwrap()).collect(); - - if a[0] % 2 == a[1] % 2 { + let a: Vec = s + .split_whitespace() + .map(|d| d.parse::().unwrap()) + .collect(); + + if a[0] % 2 == a[1] % 2 { if a[1].pow(2) > a[0] { println!("NO"); } else { diff --git a/solutions/rust/src/bin/149A.rs b/solutions/rust/src/bin/149A.rs index f59f203..6039fab 100644 --- a/solutions/rust/src/bin/149A.rs +++ b/solutions/rust/src/bin/149A.rs @@ -8,12 +8,15 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - - let mut a: Vec = s.split_whitespace().map(|d| d.parse::().unwrap()).collect(); + + let mut a: Vec = s + .split_whitespace() + .map(|d| d.parse::().unwrap()) + .collect(); a.sort(); a.reverse(); - + let mut count = 0; let mut sum = 0; diff --git a/solutions/rust/src/bin/1807A.rs b/solutions/rust/src/bin/1807A.rs index c4d5437..65092e7 100644 --- a/solutions/rust/src/bin/1807A.rs +++ b/solutions/rust/src/bin/1807A.rs @@ -3,13 +3,13 @@ use std::io; fn main() { let mut t = String::new(); io::stdin().read_line(&mut t).unwrap(); - + for _ in 1..=t.trim().parse::().unwrap() { let mut n = String::new(); io::stdin().read_line(&mut n).unwrap(); let array = n.split_whitespace().collect::>(); - + let mut int_array: Vec = vec![]; for i in array { int_array.push(i.parse::().unwrap()); diff --git a/solutions/rust/src/bin/1968A.rs b/solutions/rust/src/bin/1968A.rs index 1a75267..685d39e 100644 --- a/solutions/rust/src/bin/1968A.rs +++ b/solutions/rust/src/bin/1968A.rs @@ -3,7 +3,7 @@ use std::io; fn gcd(a: u64, b: u64) -> u64 { let mut set: [u64; 2] = [a, b]; while set[1] != 0 { - set = [set[1], set[0]%set[1]]; + set = [set[1], set[0] % set[1]]; } set[0] } @@ -25,7 +25,7 @@ fn main() { let mut maximum = 0; let mut y = 0; for j in 1..i { - let found = gcd(i,j)+j; + let found = gcd(i, j) + j; if found > maximum { y = j; maximum = found; diff --git a/solutions/rust/src/bin/200B.rs b/solutions/rust/src/bin/200B.rs index 8fdd704..bec151b 100644 --- a/solutions/rust/src/bin/200B.rs +++ b/solutions/rust/src/bin/200B.rs @@ -9,7 +9,10 @@ fn main() { let mut p = String::new(); io::stdin().read_line(&mut p).unwrap(); - let drinks = p.split_whitespace().map(|c| c.parse::().unwrap()).collect::>(); + let drinks = p + .split_whitespace() + .map(|c| c.parse::().unwrap()) + .collect::>(); let conc = drinks.iter().sum::() as f64 / n as f64; diff --git a/solutions/rust/src/bin/2044B.rs b/solutions/rust/src/bin/2044B.rs index 70b5a12..6e6f9a1 100644 --- a/solutions/rust/src/bin/2044B.rs +++ b/solutions/rust/src/bin/2044B.rs @@ -22,10 +22,10 @@ fn main() { match j { 'q' => { new.push('p'); - }, + } 'p' => { new.push('q'); - }, + } _ => { new.push('w'); } diff --git a/solutions/rust/src/bin/236A.rs b/solutions/rust/src/bin/236A.rs index a14eda6..8f12254 100644 --- a/solutions/rust/src/bin/236A.rs +++ b/solutions/rust/src/bin/236A.rs @@ -1,5 +1,5 @@ -use std::io; use std::collections::HashSet; +use std::io; fn main() { let mut s = String::new(); diff --git a/solutions/rust/src/bin/25A.rs b/solutions/rust/src/bin/25A.rs index b64ca2d..51c2fce 100644 --- a/solutions/rust/src/bin/25A.rs +++ b/solutions/rust/src/bin/25A.rs @@ -6,7 +6,10 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let a: Vec = s.split_whitespace().map(|d| d.parse::().unwrap()).collect(); + let a: Vec = s + .split_whitespace() + .map(|d| d.parse::().unwrap()) + .collect(); let mut evenness = vec![]; for i in a { @@ -20,8 +23,8 @@ fn main() { let odds = evenness.iter().filter(|&n| *n == 1).count(); if odds == 1 { - println!("{}", evenness.iter().position(|&n| n == 1).unwrap()+1); + println!("{}", evenness.iter().position(|&n| n == 1).unwrap() + 1); } else { - println!("{}", evenness.iter().position(|&n| n == 0).unwrap()+1); + println!("{}", evenness.iter().position(|&n| n == 0).unwrap() + 1); } } diff --git a/solutions/rust/src/bin/313A.rs b/solutions/rust/src/bin/313A.rs index 0e4d568..ea25365 100644 --- a/solutions/rust/src/bin/313A.rs +++ b/solutions/rust/src/bin/313A.rs @@ -13,11 +13,15 @@ fn main() { let removed: String = balance .chars() - .take(balance.len()-2) - .chain(balance.chars().skip(balance.len()-1)) + .take(balance.len() - 2) + .chain(balance.chars().skip(balance.len() - 1)) .collect(); - let options_str: [&str; 3] = [&balance[0..balance.len()-1], &removed, &balance[0..balance.len()]]; + let options_str: [&str; 3] = [ + &balance[0..balance.len() - 1], + &removed, + &balance[0..balance.len()], + ]; let options = options_str.map(|i| i.parse::().unwrap()); println!("{}", options.iter().max().unwrap()); diff --git a/solutions/rust/src/bin/318A.rs b/solutions/rust/src/bin/318A.rs index 17cb2bb..4cfddc1 100644 --- a/solutions/rust/src/bin/318A.rs +++ b/solutions/rust/src/bin/318A.rs @@ -4,17 +4,20 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let input = s.split_whitespace().map(|s| s.parse::().unwrap()).collect::>(); + let input = s + .split_whitespace() + .map(|s| s.parse::().unwrap()) + .collect::>(); let n = input[0]; let k = input[1]; - if k > ((n as f64/ 2.).ceil() as u64) { + if k > ((n as f64 / 2.).ceil() as u64) { if n % 2 == 0 { - println!("{}", (2*(k-(n/2)))) + println!("{}", (2 * (k - (n / 2)))) } else { - println!("{}", (2*(k-((n+1)/2)))) + println!("{}", (2 * (k - ((n + 1) / 2)))) } } else { - println!("{}", (2*k-1)) + println!("{}", (2 * k - 1)) } } diff --git a/solutions/rust/src/bin/337A.rs b/solutions/rust/src/bin/337A.rs index 53503a2..b727c0f 100644 --- a/solutions/rust/src/bin/337A.rs +++ b/solutions/rust/src/bin/337A.rs @@ -4,22 +4,28 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let a = s.split_whitespace().map(|s| s.parse::().unwrap()).collect::>(); + let a = s + .split_whitespace() + .map(|s| s.parse::().unwrap()) + .collect::>(); let n: usize = a[0] as usize; let m: usize = a[1] as usize; let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let mut f = s.split_whitespace().map(|s| s.parse::().unwrap()).collect::>(); + let mut f = s + .split_whitespace() + .map(|s| s.parse::().unwrap()) + .collect::>(); f.sort(); - let mut minimum = f[f.len()-1]-f[0]; + let mut minimum = f[f.len() - 1] - f[0]; - for i in 0_usize..(m-n)+1 { - let subset = &f[i..(i+n)]; - let current = subset[subset.len()-1]-subset[0]; + for i in 0_usize..(m - n) + 1 { + let subset = &f[i..(i + n)]; + let current = subset[subset.len() - 1] - subset[0]; if current < minimum { minimum = current; } @@ -27,4 +33,3 @@ fn main() { println!("{}", minimum); } - diff --git a/solutions/rust/src/bin/339A.rs b/solutions/rust/src/bin/339A.rs index 755c168..8617f31 100644 --- a/solutions/rust/src/bin/339A.rs +++ b/solutions/rust/src/bin/339A.rs @@ -4,7 +4,11 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let mut nums = s.trim().split('+').map(String::from).collect::>(); + let mut nums = s + .trim() + .split('+') + .map(String::from) + .collect::>(); nums.sort(); diff --git a/solutions/rust/src/bin/34B.rs b/solutions/rust/src/bin/34B.rs index 4f501ba..3049b38 100644 --- a/solutions/rust/src/bin/34B.rs +++ b/solutions/rust/src/bin/34B.rs @@ -4,13 +4,21 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let a1 = s.trim().split_whitespace().map(|i| i.parse::().unwrap()).collect::>(); + let a1 = s + .trim() + .split_whitespace() + .map(|i| i.parse::().unwrap()) + .collect::>(); let max = a1[1]; let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let mut a2 = s.trim().split_whitespace().map(|i| i.parse::().unwrap()).collect::>(); + let mut a2 = s + .trim() + .split_whitespace() + .map(|i| i.parse::().unwrap()) + .collect::>(); let mut cost = 0; let mut count = 0; @@ -18,10 +26,10 @@ fn main() { for i in a2 { if count == max { - println!("{}", -1*cost); + println!("{}", -1 * cost); std::process::exit(0); - } else if cost+i > cost { - println!("{}", -1*cost); + } else if cost + i > cost { + println!("{}", -1 * cost); std::process::exit(0); } else { count += 1; @@ -29,5 +37,5 @@ fn main() { } } - println!("{}", -1*cost); + println!("{}", -1 * cost); } diff --git a/solutions/rust/src/bin/405A.rs b/solutions/rust/src/bin/405A.rs index b11475f..65c88e8 100644 --- a/solutions/rust/src/bin/405A.rs +++ b/solutions/rust/src/bin/405A.rs @@ -7,11 +7,17 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let mut initial = s.split_whitespace().map(|s| s.parse::().unwrap()).collect::>(); + let mut initial = s + .split_whitespace() + .map(|s| s.parse::().unwrap()) + .collect::>(); initial.sort(); - let output = initial.iter().map(|d| d.to_string()).collect::>(); + let output = initial + .iter() + .map(|d| d.to_string()) + .collect::>(); println!("{}", output.join(" ")); } diff --git a/solutions/rust/src/bin/451A.rs b/solutions/rust/src/bin/451A.rs index 58853cf..01e05a4 100644 --- a/solutions/rust/src/bin/451A.rs +++ b/solutions/rust/src/bin/451A.rs @@ -4,23 +4,26 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let a = s.split_whitespace().map(|i| i.parse::().unwrap()).collect::>(); + let a = s + .split_whitespace() + .map(|i| i.parse::().unwrap()) + .collect::>(); let mut n = a[0]; let mut m = a[1]; - let mut intersections = n*m; + let mut intersections = n * m; let mut steps = 0; while intersections > 0 { - intersections -= (n+m)-1; + intersections -= (n + m) - 1; n -= 1; m -= 1; steps += 1; } - if (steps+1) % 2 == 0 { + if (steps + 1) % 2 == 0 { println!("Akshat"); } else { println!("Malvika"); diff --git a/solutions/rust/src/bin/466A.rs b/solutions/rust/src/bin/466A.rs index 5d2b6ff..153d95f 100644 --- a/solutions/rust/src/bin/466A.rs +++ b/solutions/rust/src/bin/466A.rs @@ -4,8 +4,12 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let inp = s.trim().split_whitespace().map(|i| i.parse::().unwrap()).collect::>(); - + let inp = s + .trim() + .split_whitespace() + .map(|i| i.parse::().unwrap()) + .collect::>(); + let n = inp[0]; let m = inp[1]; let a = inp[2]; @@ -14,16 +18,16 @@ fn main() { let mut price: f64; if b > a { - price = b * (n/m).floor() + a * (n%m); - if m > n && n*a > b { + price = b * (n / m).floor() + a * (n % m); + if m > n && n * a > b { price = b; - } else if n*a < b && n*a < price { + } else if n * a < b && n * a < price { price = a; - } else if n*a < price { - price = n*a; + } else if n * a < price { + price = n * a; } } else { - price = b * (n/m).ceil(); + price = b * (n / m).ceil(); } println!("{}", price); diff --git a/solutions/rust/src/bin/580A.rs b/solutions/rust/src/bin/580A.rs index e165de6..34d9629 100644 --- a/solutions/rust/src/bin/580A.rs +++ b/solutions/rust/src/bin/580A.rs @@ -3,18 +3,21 @@ use std::io; fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let n = s.trim().parse::().unwrap(); + let n = s.trim().parse::().unwrap(); let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let a = s.split_whitespace().map(|n| n.parse::().unwrap()).collect::>(); + let a = s + .split_whitespace() + .map(|n| n.parse::().unwrap()) + .collect::>(); let mut maximum = 1; let mut count = 1; for i in 1..n { - if a[i] >= a[i-1] { + if a[i] >= a[i - 1] { count += 1; if count > maximum { maximum = count; diff --git a/solutions/rust/src/bin/598A.rs b/solutions/rust/src/bin/598A.rs index e5d555f..b30d5f3 100644 --- a/solutions/rust/src/bin/598A.rs +++ b/solutions/rust/src/bin/598A.rs @@ -14,7 +14,7 @@ fn main() { let n: i64 = s.trim().parse().unwrap(); - total += n*(n+1)/2; + total += n * (n + 1) / 2; let mut exponent = 0; while 2_i64.pow(exponent) <= n { @@ -25,5 +25,4 @@ fn main() { println!("{}", total); total = 0; } - } diff --git a/solutions/rust/src/bin/617A.rs b/solutions/rust/src/bin/617A.rs index 1f3927e..059be7d 100644 --- a/solutions/rust/src/bin/617A.rs +++ b/solutions/rust/src/bin/617A.rs @@ -12,5 +12,5 @@ fn main() { count += 1; } - println!("{}", count); + println!("{}", count); } diff --git a/solutions/rust/src/bin/705A.rs b/solutions/rust/src/bin/705A.rs index 0cf98ec..dd1c2f2 100644 --- a/solutions/rust/src/bin/705A.rs +++ b/solutions/rust/src/bin/705A.rs @@ -8,7 +8,7 @@ fn main() { let mut words = String::from("I hate"); - for i in 0..(n-1) { + for i in 0..(n - 1) { if i % 2 == 0 { words += &String::from(" that I love"); } else { diff --git a/solutions/rust/src/bin/791A.rs b/solutions/rust/src/bin/791A.rs index c369471..1bf4362 100644 --- a/solutions/rust/src/bin/791A.rs +++ b/solutions/rust/src/bin/791A.rs @@ -4,7 +4,10 @@ fn main() { let mut s = String::new(); io::stdin().read_line(&mut s).unwrap(); - let a = s.split_whitespace().map(|s| s.parse::().unwrap()).collect::>(); + let a = s + .split_whitespace() + .map(|s| s.parse::().unwrap()) + .collect::>(); let mut l = a[0]; let mut b = a[1];