cargo: fmt

This commit is contained in:
Muhammad Nauman Raza 2025-02-09 13:19:50 +00:00
parent 5b99663d99
commit 387cbcb94c
Signed by: devraza
GPG key ID: 91EAD6081011574B
22 changed files with 120 additions and 63 deletions

View file

@ -11,9 +11,12 @@ fn main() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let s: Vec<i64> = s.split_whitespace().map(|d| d.parse::<i64>().unwrap()).collect();
let s: Vec<i64> = s
.split_whitespace()
.map(|d| d.parse::<i64>().unwrap())
.collect();
people += s[1]-s[0];
people += s[1] - s[0];
if people > maximum {
maximum = people;

View file

@ -9,9 +9,12 @@ fn main() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let a: Vec<u64> = s.split_whitespace().map(|d| d.parse::<u64>().unwrap()).collect();
if a[0] % 2 == a[1] % 2 {
let a: Vec<u64> = s
.split_whitespace()
.map(|d| d.parse::<u64>().unwrap())
.collect();
if a[0] % 2 == a[1] % 2 {
if a[1].pow(2) > a[0] {
println!("NO");
} else {

View file

@ -8,12 +8,15 @@ fn main() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let mut a: Vec<u64> = s.split_whitespace().map(|d| d.parse::<u64>().unwrap()).collect();
let mut a: Vec<u64> = s
.split_whitespace()
.map(|d| d.parse::<u64>().unwrap())
.collect();
a.sort();
a.reverse();
let mut count = 0;
let mut sum = 0;

View file

@ -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::<i16>().unwrap() {
let mut n = String::new();
io::stdin().read_line(&mut n).unwrap();
let array = n.split_whitespace().collect::<Vec<&str>>();
let mut int_array: Vec<i8> = vec![];
for i in array {
int_array.push(i.parse::<i8>().unwrap());

View file

@ -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;

View file

@ -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::<u64>().unwrap()).collect::<Vec<u64>>();
let drinks = p
.split_whitespace()
.map(|c| c.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
let conc = drinks.iter().sum::<u64>() as f64 / n as f64;

View file

@ -22,10 +22,10 @@ fn main() {
match j {
'q' => {
new.push('p');
},
}
'p' => {
new.push('q');
},
}
_ => {
new.push('w');
}

View file

@ -1,5 +1,5 @@
use std::io;
use std::collections::HashSet;
use std::io;
fn main() {
let mut s = String::new();

View file

@ -6,7 +6,10 @@ fn main() {
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let a: Vec<u64> = s.split_whitespace().map(|d| d.parse::<u64>().unwrap()).collect();
let a: Vec<u64> = s
.split_whitespace()
.map(|d| d.parse::<u64>().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);
}
}

View file

@ -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::<i64>().unwrap());
println!("{}", options.iter().max().unwrap());

View file

@ -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::<u64>().unwrap()).collect::<Vec<u64>>();
let input = s
.split_whitespace()
.map(|s| s.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
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))
}
}

View file

@ -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::<u64>().unwrap()).collect::<Vec<u64>>();
let a = s
.split_whitespace()
.map(|s| s.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
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::<u64>().unwrap()).collect::<Vec<u64>>();
let mut f = s
.split_whitespace()
.map(|s| s.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
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);
}

View file

@ -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::<Vec<String>>();
let mut nums = s
.trim()
.split('+')
.map(String::from)
.collect::<Vec<String>>();
nums.sort();

View file

@ -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::<i64>().unwrap()).collect::<Vec<i64>>();
let a1 = s
.trim()
.split_whitespace()
.map(|i| i.parse::<i64>().unwrap())
.collect::<Vec<i64>>();
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::<i64>().unwrap()).collect::<Vec<i64>>();
let mut a2 = s
.trim()
.split_whitespace()
.map(|i| i.parse::<i64>().unwrap())
.collect::<Vec<i64>>();
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);
}

View file

@ -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::<u64>().unwrap()).collect::<Vec<u64>>();
let mut initial = s
.split_whitespace()
.map(|s| s.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
initial.sort();
let output = initial.iter().map(|d| d.to_string()).collect::<Vec<String>>();
let output = initial
.iter()
.map(|d| d.to_string())
.collect::<Vec<String>>();
println!("{}", output.join(" "));
}

View file

@ -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::<i64>().unwrap()).collect::<Vec<i64>>();
let a = s
.split_whitespace()
.map(|i| i.parse::<i64>().unwrap())
.collect::<Vec<i64>>();
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");

View file

@ -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::<f64>().unwrap()).collect::<Vec<f64>>();
let inp = s
.trim()
.split_whitespace()
.map(|i| i.parse::<f64>().unwrap())
.collect::<Vec<f64>>();
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);

View file

@ -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::<usize>().unwrap();
let n = s.trim().parse::<usize>().unwrap();
let mut s = String::new();
io::stdin().read_line(&mut s).unwrap();
let a = s.split_whitespace().map(|n| n.parse::<u64>().unwrap()).collect::<Vec<u64>>();
let a = s
.split_whitespace()
.map(|n| n.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
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;

View file

@ -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;
}
}

View file

@ -12,5 +12,5 @@ fn main() {
count += 1;
}
println!("{}", count);
println!("{}", count);
}

View file

@ -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 {

View file

@ -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::<u64>().unwrap()).collect::<Vec<u64>>();
let a = s
.split_whitespace()
.map(|s| s.parse::<u64>().unwrap())
.collect::<Vec<u64>>();
let mut l = a[0];
let mut b = a[1];