chore: init with current solutions

This commit is contained in:
Muhammad Nauman Raza 2025-01-11 11:41:29 +00:00
commit 21e6d3de32
Signed by: devraza
GPG key ID: 91EAD6081011574B
26 changed files with 475 additions and 0 deletions

9
solutions/ab_again.py Normal file
View file

@ -0,0 +1,9 @@
t = int(input())
for _ in range(t):
n = list(input())
count = 0
for i in n:
count += int(i)
print(count)

View file

@ -0,0 +1,7 @@
a = input().split(' ')
s = input()
count = 0
for i in s:
count += int(a[int(i)-1])
print(count)

View file

@ -0,0 +1,8 @@
t = int(input())
for _ in range(t):
resident = input()
pressed = 0
pressed += int((int(resident[0])-1)*10 + (len(resident)/2)*(len(resident)+1))
print(pressed)

View file

@ -0,0 +1,8 @@
t = int(input())
for _ in range(t):
a, b = [list(x) for x in input().split()]
a[0], b[0] = b[0], a[0]
print(''.join(c for c in a),''.join(c for c in b))

View file

@ -0,0 +1,21 @@
import string, itertools
t = int(input())
for _ in range(t):
n = int(input())
s = input()
filtered = []
s = ''.join(i for i, _ in itertools.groupby(s))
check = True
for i in string.ascii_uppercase:
if s.count(i) > 1:
check = False
break
if check:
print("YES")
else:
print("NO")

View file

@ -0,0 +1,14 @@
t = int(input())
for _ in range(t):
count = int(input())
weights = [int(x) for x in input().split(" ")]
if count % 2 != 0 and min(weights) == max(weights):
print("NO")
continue
elif sum(weights) % 2 != 0:
print("NO")
continue
else:
print("YES")

14
solutions/games.py Normal file
View file

@ -0,0 +1,14 @@
n = int(input())
uniforms = []
for _ in range(n):
h, a = input().split(' ')
uniforms.append([h,a])
count = 0
for idx_i, i in enumerate(uniforms):
for idx_j, j in enumerate(uniforms):
if idx_i != idx_j and i[0] == j[1]:
count += 1
print(count)

View file

@ -0,0 +1,7 @@
n = input()
opinions = [int(x) for x in input().split(' ')]
if 1 in opinions:
print("HARD")
else:
print("EASY")

10
solutions/love_story.py Normal file
View file

@ -0,0 +1,10 @@
t = int(input())
s = "codeforces"
for _ in range(t):
indices = 0
case = input()
for i in range(len(case)):
if case[i] != s[i]:
indices += 1
print(indices)

View file

@ -0,0 +1,26 @@
t = int(input())
sizes = []
def square(size):
size.sort()
if size[0] == size[1]:
return (size[0]*2)**2
if size[0]*2 <= size[1]:
return max(size)**2
while size[1] % size[0] != 0:
size[1] += 1
return size[1]**2;
for i in range(t):
size = [int(x) for x in input().split(" ")]
print(square(size))
"""
def check():
for i in range(1, 101):
for j in range(1, 101):
if square([i,j]) == 36 and i != 6 and j != 6:
print(i,j)
check()
"""

10
solutions/minimize.py Normal file
View file

@ -0,0 +1,10 @@
t = int(input())
for _ in range(t):
a,b = [int(x) for x in input().split(" ")]
minimum = b
for c in range(a,b+1):
value = (c-a)+(b-c)
if value < minimum:
minimum = value
print(minimum)

View file

@ -0,0 +1,19 @@
n = int(input())
mishka = 0
chris = 0
for _ in range(n):
m, c = [int(x) for x in input().split(' ')]
if m > c:
mishka += 1
elif c > m:
chris += 1
if mishka > chris:
print("Mishka")
elif chris > mishka:
print("Chris")
else:
print("Friendship is magic!^^")

14
solutions/pangram.py Normal file
View file

@ -0,0 +1,14 @@
import string
n = input()
s = input().lower()
check = True
for i in string.ascii_lowercase:
if s.count(i) == 0:
check = False
if check:
print("YES")
else:
print("NO")

View file

@ -0,0 +1,7 @@
t = int(input())
for _ in range(t):
n = input()
a = [int(n) for n in input().split(' ')]
print(max(a)-min(a))

View file

@ -0,0 +1,16 @@
t = int(input())
def check(c1,c2):
if c1+(2*c2) != n:
if (c1+1)+(2*c2) == n:
return c1+1,c2
elif c1+(2*(c2+1)) == n:
return c1,c2+1
else:
return c1,c2
for _ in range(t):
n = int(input())
c1,c2 = [n//3, n//3]
print(' '.join(str(x) for x in check(c1,c2)))

View file

@ -0,0 +1,11 @@
t = int(input())
for _ in range(t):
x, y, n=[int(x) for x in input().split()]
k=n % x
if k > y:
print(n-k+y)
elif k == y:
print(n)
else:
print(n-k-x+y)

66
solutions/rust/1881A.rs Normal file
View file

@ -0,0 +1,66 @@
use std::io;
fn share_char(a: &str, b: &str) -> bool {
let set_a: Vec<char> = a.chars().collect();
let set_b: Vec<char> = b.chars().collect();
let mut check = true;
for i in set_a.iter() {
let mut subcheck = false;
for j in set_b.iter() {
if i == j {
subcheck = true;
}
}
if subcheck == false {
check = false;
} else {
check = true;
}
}
check
}
fn main() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
let mut strings: Vec<[String; 2]> = vec![];
for _ in 1..=t.trim().parse::<u64>().unwrap() {
let mut nm = String::new();
io::stdin().read_line(&mut nm).unwrap();
let nm_vec: Vec<&str> = nm.trim().split_whitespace().collect();
let mut nm_array: [u64; 2] = [0, 0];
for i in 0..=1 {
nm_array[i] = nm_vec[i].parse::<u64>().unwrap();
}
let mut string_vec: [String; 2] = [String::new(), String::new()];
for i in 0..=1 {
let mut string = String::new();
io::stdin().read_line(&mut string).unwrap();
string_vec[i] = string.trim().to_string();
}
strings.push(string_vec);
}
for i in 0..strings.len() {
if !share_char(&strings[i][0], &strings[i][1]) {
println!("-1");
} else {
let mut counter = 0;
while !strings[i][0].contains(&strings[i][1]) {
strings[i][0] = strings[i][0].repeat(2);
counter += 1;
if counter > 25 {
counter = 0;
break;
}
}
println!("{}", counter);
}
}
}

40
solutions/rust/1968A.rs Normal file
View file

@ -0,0 +1,40 @@
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[0]
}
fn main() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
let mut inputs: Vec<u64> = vec![];
for _ in 1..=t.trim().parse::<u64>().unwrap() {
let mut case = String::new();
io::stdin().read_line(&mut case).unwrap();
inputs.push(case.trim().parse::<u64>().unwrap());
}
let mut outputs: Vec<u64> = vec![];
for i in inputs {
let mut maximum = 0;
let mut y = 0;
for j in 1..i {
let found = gcd(i,j)+j;
if found > maximum {
y = j;
maximum = found;
}
}
outputs.push(y);
}
for i in outputs {
println!("{}", i);
}
}

40
solutions/rust/2044B.rs Normal file
View file

@ -0,0 +1,40 @@
use std::io;
fn main() {
let mut t = String::new();
io::stdin().read_line(&mut t).unwrap();
let mut strings: Vec<String> = vec![];
for _ in 1..=t.trim().parse::<u64>().unwrap() {
let mut a = String::new();
io::stdin().read_line(&mut a).unwrap();
strings.push(a.trim().to_string());
}
let mut outputs: Vec<String> = vec![];
for i in strings {
let original = i.chars().rev();
let mut new = String::new();
for j in original {
match j {
'q' => {
new.push_str("p");
},
'p' => {
new.push_str("q");
},
_ => {
new.push_str("w");
}
}
}
outputs.push(new);
}
for i in outputs {
println!("{}", i);
}
}

25
solutions/short_sort.py Normal file
View file

@ -0,0 +1,25 @@
t = int(input())
for _ in range(t):
s = input()
s = [s[0], s[1], s[2]]
original = s[:]
check = False
s[0], s[2] = s[2], s[0]
if ''.join(c for c in s) == "abc" or ''.join(c for c in original) == "abc":
check = True
else:
s = original[:]
s[0], s[1] = s[1], s[0]
if ''.join(c for c in s) == "abc":
check = True
else:
s = original[:]
s[1], s[2] = s[2], s[1]
if ''.join(c for c in s) == "abc":
check = True
if check:
print("YES")
else:
print("NO")

View file

@ -0,0 +1,14 @@
t = int(input())
for _ in range(t):
b = list(input())
original = b[:]
b.pop(0)
b.pop(len(b)-1)
copied = []
for idx, i in enumerate(b):
if idx % 2 == 0:
copied.append(i)
print(f"{original[0]}{''.join(c for c in copied)}{original[len(original)-1]}")

16
solutions/spell_check.py Normal file
View file

@ -0,0 +1,16 @@
from itertools import permutations
t = int(input())
perms = [''.join(x) for x in permutations("Timur", 5)]
for _ in range(t):
n = int(input())
s = input()
if n != 5:
print("NO")
elif s in perms:
print("YES")
else:
print("NO")

View file

@ -0,0 +1,10 @@
t = int(input())
for _ in range(t):
s = input()
if len(s) % 2 != 0:
print("NO")
elif s[0:len(s)//2] == s[len(s)//2:len(s)]:
print("YES")
else:
print("NO")

View file

@ -0,0 +1,8 @@
from math import ceil
n, m, a = [int(x) for x in input().split(' ')]
val1 = ceil(n/a)
val2 = ceil(m/a)
print(val1*val2)

View file

@ -0,0 +1,10 @@
n = int(input())
for _ in range(n):
word = input()
if len(word) > 10:
output = word[0] + str(len(word)-2) + word[len(word)-1]
print(output)
else:
print(word)

45
solutions/winner.py Normal file
View file

@ -0,0 +1,45 @@
n = int(input())
scores = {}
orders = []
for _ in range(n):
name, score = input().split(' ')
orders.append([name, int(score)])
if name not in scores:
scores[name] = []
scores[name].append(int(score))
totals = []
for k,v in scores.items():
totals.append(sum(v))
winval = max(totals)
winners = [k for k,v in scores.items() if sum(v) == winval]
if len(winners) < 1:
print(winner[0])
else:
for idx, i in enumerate(orders):
if i[0] not in winners:
del orders[idx]
for idx, i in enumerate(orders):
if i[0] not in winners:
del orders[idx]
print(orders)
winner = ''
durations = {}
for i in orders:
if i[0] not in durations:
durations[i[0]] = 0
durations[i[0]] += i[1]
if durations[i[0]] == winval:
winner = i[0]
break
print(winner)