commit 21e6d3de329d29e92f192239d07669d4ce87d58c Author: Muhammad Nauman Raza Date: Sat Jan 11 11:41:29 2025 +0000 chore: init with current solutions diff --git a/solutions/ab_again.py b/solutions/ab_again.py new file mode 100644 index 0000000..0271032 --- /dev/null +++ b/solutions/ab_again.py @@ -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) diff --git a/solutions/black_square.py b/solutions/black_square.py new file mode 100644 index 0000000..739acc7 --- /dev/null +++ b/solutions/black_square.py @@ -0,0 +1,7 @@ +a = input().split(' ') +s = input() + +count = 0 +for i in s: + count += int(a[int(i)-1]) +print(count) diff --git a/solutions/boring_apartments.py b/solutions/boring_apartments.py new file mode 100644 index 0000000..6be1168 --- /dev/null +++ b/solutions/boring_apartments.py @@ -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) diff --git a/solutions/creating_words.py b/solutions/creating_words.py new file mode 100644 index 0000000..91983df --- /dev/null +++ b/solutions/creating_words.py @@ -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)) diff --git a/solutions/do_not_be_distracted.py b/solutions/do_not_be_distracted.py new file mode 100644 index 0000000..b172d75 --- /dev/null +++ b/solutions/do_not_be_distracted.py @@ -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") diff --git a/solutions/fair_division.py b/solutions/fair_division.py new file mode 100644 index 0000000..1a0b600 --- /dev/null +++ b/solutions/fair_division.py @@ -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") diff --git a/solutions/games.py b/solutions/games.py new file mode 100644 index 0000000..d786c82 --- /dev/null +++ b/solutions/games.py @@ -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) diff --git a/solutions/in_search_of_an_easy_problem.py b/solutions/in_search_of_an_easy_problem.py new file mode 100644 index 0000000..c458078 --- /dev/null +++ b/solutions/in_search_of_an_easy_problem.py @@ -0,0 +1,7 @@ +n = input() +opinions = [int(x) for x in input().split(' ')] + +if 1 in opinions: + print("HARD") +else: + print("EASY") diff --git a/solutions/love_story.py b/solutions/love_story.py new file mode 100644 index 0000000..2312827 --- /dev/null +++ b/solutions/love_story.py @@ -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) diff --git a/solutions/minimal_square.py b/solutions/minimal_square.py new file mode 100644 index 0000000..892f9a0 --- /dev/null +++ b/solutions/minimal_square.py @@ -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() +""" diff --git a/solutions/minimize.py b/solutions/minimize.py new file mode 100644 index 0000000..3f79fa9 --- /dev/null +++ b/solutions/minimize.py @@ -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) diff --git a/solutions/mishka_and_game.py b/solutions/mishka_and_game.py new file mode 100644 index 0000000..6820625 --- /dev/null +++ b/solutions/mishka_and_game.py @@ -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!^^") diff --git a/solutions/pangram.py b/solutions/pangram.py new file mode 100644 index 0000000..17fe415 --- /dev/null +++ b/solutions/pangram.py @@ -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") diff --git a/solutions/plus_one_on_the_subset.py b/solutions/plus_one_on_the_subset.py new file mode 100644 index 0000000..d9c1c87 --- /dev/null +++ b/solutions/plus_one_on_the_subset.py @@ -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)) diff --git a/solutions/polycarp_and_coins.py b/solutions/polycarp_and_coins.py new file mode 100644 index 0000000..74bb2bd --- /dev/null +++ b/solutions/polycarp_and_coins.py @@ -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))) diff --git a/solutions/required_remainder.py b/solutions/required_remainder.py new file mode 100644 index 0000000..b07f2ad --- /dev/null +++ b/solutions/required_remainder.py @@ -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) diff --git a/solutions/rust/1881A.rs b/solutions/rust/1881A.rs new file mode 100644 index 0000000..38452aa --- /dev/null +++ b/solutions/rust/1881A.rs @@ -0,0 +1,66 @@ +use std::io; + +fn share_char(a: &str, b: &str) -> bool { + let set_a: Vec = a.chars().collect(); + let set_b: Vec = 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::().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::().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); + } + } +} diff --git a/solutions/rust/1968A.rs b/solutions/rust/1968A.rs new file mode 100644 index 0000000..1a75267 --- /dev/null +++ b/solutions/rust/1968A.rs @@ -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 = vec![]; + + for _ in 1..=t.trim().parse::().unwrap() { + let mut case = String::new(); + io::stdin().read_line(&mut case).unwrap(); + inputs.push(case.trim().parse::().unwrap()); + } + + let mut outputs: Vec = 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); + } +} diff --git a/solutions/rust/2044B.rs b/solutions/rust/2044B.rs new file mode 100644 index 0000000..4dd1622 --- /dev/null +++ b/solutions/rust/2044B.rs @@ -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 = vec![]; + + for _ in 1..=t.trim().parse::().unwrap() { + let mut a = String::new(); + io::stdin().read_line(&mut a).unwrap(); + + strings.push(a.trim().to_string()); + } + + let mut outputs: Vec = 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); + } +} diff --git a/solutions/short_sort.py b/solutions/short_sort.py new file mode 100644 index 0000000..57b278a --- /dev/null +++ b/solutions/short_sort.py @@ -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") diff --git a/solutions/short_substrings.py b/solutions/short_substrings.py new file mode 100644 index 0000000..06d02e3 --- /dev/null +++ b/solutions/short_substrings.py @@ -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]}") diff --git a/solutions/spell_check.py b/solutions/spell_check.py new file mode 100644 index 0000000..7cb2e60 --- /dev/null +++ b/solutions/spell_check.py @@ -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") diff --git a/solutions/square_string.py b/solutions/square_string.py new file mode 100644 index 0000000..5606222 --- /dev/null +++ b/solutions/square_string.py @@ -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") diff --git a/solutions/theatre_square.py b/solutions/theatre_square.py new file mode 100644 index 0000000..868ae6f --- /dev/null +++ b/solutions/theatre_square.py @@ -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) diff --git a/solutions/way_too_long_words.py b/solutions/way_too_long_words.py new file mode 100644 index 0000000..200d238 --- /dev/null +++ b/solutions/way_too_long_words.py @@ -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) diff --git a/solutions/winner.py b/solutions/winner.py new file mode 100644 index 0000000..52cba47 --- /dev/null +++ b/solutions/winner.py @@ -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)