0% found this document useful (0 votes)
1 views

Winter Code Clash- Problem Set

Uploaded by

exegunslinger
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Winter Code Clash- Problem Set

Uploaded by

exegunslinger
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

WINTER CODE CLASH

Organized by: South Asia Computer Club

Programming Contest Problem set

1. Roman Numeral Converter

Roman numerals are represented by seven different symbols:


●​ I=1
●​ V=5
●​ X = 10
●​ L = 50
●​ C = 100
●​ D = 500
●​ M = 1000

Roman numerals are usually written from largest to smallest from left to right. However, in
certain cases, subtraction is used to represent numbers. For example:
●​ IV = 4 (5 - 1)
●​ IX = 9 (10 - 1)
●​ XL = 40 (50 - 10)
●​ XC = 90 (100 - 10)
●​ CD = 400 (500 - 100)
●​ CM = 900 (1000 - 100)

Your task is to convert a given Roman numeral string to an integer.

Input:
●​ A Roman numeral string s (1 ≤ length of s ≤ 15), consisting of the symbols 'I', 'V', 'X', 'L',
'C', 'D', 'M'.

Output:
●​ The integer value of the given Roman numeral.

Example:
Input Output Explanation

III 3 III = 1 + 1 + 1 = 3

LVIII 58 L = 50, V = 5, III = 3, so 50 + 5 + 3 = 58.

MCMXCIV 1994 M = 1000, CM = 900, XC = 90, IV = 4, so 1000 + 900 + 90 + 4


= 1994.

2. Game Selection
Four friends decide to play some games. They will play a game if at least three of them agree to
it. You are given the opinions of the four friends for mmm games. Your task is to count how
many games they will play.

Input:
●​ The first line contains an integer mmm (1≤m≤10001 \leq m \leq 10001≤m≤1000) — the
number of games.
●​ The next mmm lines contain four integers (0 or 1) separated by spaces. Each number
represents a friend’s agreement (1 = agrees, 0 = disagrees).

Output:
●​ Print the number of games they will play.

Example:

Input Output

3​ 2
1 1 1 0​
1 1 0 0​
1111

3. Valid Parentheses

Given a string S containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input
string is valid. A string is considered valid if:

a.​ Open brackets must be closed by the same type of brackets.


b.​ Open brackets must be closed in the correct order.
c.​ Every closing bracket has a corresponding opening bracket of the same type.
Input:
●​ A string S consisting of the characters '(', ')', '{', '}', '[' and ']'.
●​ The string will only contain the aforementioned characters.

Output:
●​ Print true if the input string is valid, otherwise, print false.

Constraints:

●​ The length of the string is between 1 and 10^4.

Example:

Input Output

() true

()[]{} true

(] false

([]) true

4. Username Mood

In a gaming community, usernames often reveal the mood of the player. The mood is
determined by counting the number of distinct letters in their username:
●​ If the number of distinct letters is even, the mood is "HAPPY!".
●​ If the number of distinct letters is odd, the mood is "ANGRY!".

Input:
●​ A single line containing a username — a non-empty string of lowercase English letters (at
most 100 characters).

Output:
●​ Print "HAPPY!" if the number of distinct letters is even.
●​ Print "ANGRY!" if the number of distinct letters is odd.
Example:

Input Output

gamerzone HAPPY!

proplayer ANGRY!

5. Reverse the String

Write a program that takes a string as input and returns the string in reverse order.

Input:
●​ A string s of length n (1 ≤ n ≤ 1000), consisting of lowercase Latin letters and/or spaces.

Output:
●​ The string S reversed.

Example:

Input Output

hello olleh

world dlrow

race car rac ecar

Constraints:
●​ The length of the string S is at least 1 and at most 1000.
●​ The string may contain spaces between characters.

6. Balanced Lucky Number


A number is called lucky if it contains only the digits 4 and 7. A lucky number is called balanced
if the sum of the first half of its digits equals the sum of the second half.
Given a number, determine if it is a balanced lucky number.

Input:
●​ The first line contains an even integer 𝑛 (2≤𝑛≤50) — the length of the number.
●​ The second line contains an n-digit number (it may have leading zeros).
Output:
●​ Print "YES" if the number is a balanced lucky number.
●​ Otherwise, print "NO".

Examples:

Input Output Explanation

4 YES The number is lucky, and the sum of the first half 4+4=84 + 4 =
4477 84+4=8 equals the sum of the second half 7+7=87 + 7 = 87+7=8. So,
the number is balanced.

6 NO The number is lucky, the sums 7+7+4=187 + 7 + 4 = 187+7+4=18 and


774477 4+7+7=184 + 7 + 7 = 184+7+7=18 are not equal.

7. Divisor Words
Given a number 𝑁 (1 𝑡ℎ𝑟𝑜𝑢𝑔ℎ 1000), print:
●​ "Alpha" if the number is divisible by 4,
●​ "Beta" if the number is divisible by 6,
●​ "AlphaBeta" if the number is divisible by both 4 and 6.
●​ If none of these conditions are true, print nothing.

Input:
A single line contains a positive integer 𝑁 (1≤𝑁≤1000).

Output:
Print "Alpha", "Beta", "AlphaBeta", or nothing, depending on the conditions.

Examples:

Input Output

8 Alpha

18 Beta

24 AlphaBeta

7
8. Remove Duplicate Numbers from an Array
In a small town, a local store sells a variety of numbered items, and each item is uniquely
identified by a number. One day, the store owner noticed that some of the items were repeated
in the inventory list, making it difficult to track how many unique items they had in stock.

The store owner asked for your help to organize the inventory by removing duplicate items. Your
task is to take the inventory list and return a new list that contains only the unique items,
maintaining the order in which they first appeared.

Input:
You are given an array of integers representing the inventory list. Some items might be repeated.

Output:
A new list containing only the unique integers from the original list, preserving the order of their
first occurrence.
Example:
1.​ Input: [1, 2, 3, 1, 2, 3, 4, 5, 5, 7, 3, 4]​
Output: [1, 2, 3, 4, 5, 7]
2.​ Input: [10, 20, 20, 10, 30]​
Output: [10, 20, 30]
3.​ Input: [1, 1, 1, 1, 1]​
Output: [1]

9. Odd or Even
In a small village, there is a tradition where people gather around and play a number game every
evening. The villagers take turns picking a number, and everyone needs to determine whether
the number is odd or even. The village elder, who loves puzzles, has asked you to help with the
game.
Your task is simple: given a number, you need to determine whether it is odd or even.

Input:
●​ A single integer, N, is provided.

Output:
●​ Print "Odd" if the number is odd, and "Even" if the number is even.

Example:

1.​ Input: 5​
Output: Odd
2.​ Input: 10​
Output: Even
3.​ Input: 7​
Output: Odd

10. Helping the Farmer


Write a program that takes an integer M. If the number is greater than or equal to 0, print
"Happy Farmer!", otherwise print "-1".

Input:
1.​ The first line contains an integer K, the total number of test cases.
2.​ The next K lines each contain an integer M.

Output:
For each test case, output the given string or "-1", each on a new line.

Constraints:
●​ 1≤𝐾≤1000
●​ − 50≤𝑀≤50

Example:

Input Output

4 Happy Farmer!
5 -1
-3 Happy Farmer!
0 Happy Farmer!
10

11. Swap Numbers


In the village of Numerville, two friends, Tom and Jerry, love solving puzzles. One day, they
found a challenge where they needed to swap two numbers to complete a task. Curious, they
decided to help each other out and solve this puzzle.

Your task is to swap the two given numbers and print them in the new order.

Input:
●​ Two integers, a and b, are provided.
Output:
●​ Print the two integers, b and a, in the swapped order.

Example:
1.​ Input: 5 10​
Output: 10 5
2.​ Input: 2 7​
Output: 7 2

12. Counting a Character


Write a program that reads a character C and a text S, then prints the number of times the
character C appears in S.

The character match should be case-insensitive.

Constraints:

●​ The length of 𝐶 = 1.
●​ S consists of lower and upper case letters, digits, and spaces.
●​ S may span multiple lines, and the input ends with "END_OF_TEXT".

Input:
●​ The first line contains the character C.
●​ The following lines contain the text S, ending with "END_OF_TEXT".

Output:
Print the count of C in the text S.

Example:

Input Output

e 8
Everyone excels in execution
Endurance, effort, and excellence
END_OF_TEXT

13. Count Divisors


In the kingdom of Numerica, the wise king assigned a challenge to his royal mathematician. The
king gave him three numbers: a, b, and c. The mathematician was asked to find how many
numbers between a and b (inclusive) divide c without leaving a remainder. The king was very
curious to know the answer!

Your task is to help the mathematician solve this puzzle by counting the divisors of c that lie
between a and b.

Input:
Three integers a, b, and c are given in a single line, separated by spaces.

Output:
Print the number of divisors of c that lie in the range from a to b (inclusive).
Constraints:

●​ 1≤𝑎, 𝑏, 𝑐≤10000
●​ 𝑎≤𝑏

Example:

1.​ Input: 5 14 80​


Output: 3​
Explanation: The divisors of 80 between 5 and 14 are 5, 8, and 10.
2.​ Input: 1 10 36​
Output: 4​
Explanation: The divisors of 36 between 1 and 10 are 1, 2, 3, 6.
3.​ Input: 3 7 28​
Output: 2​
Explanation: The divisors of 28 between 3 and 7 are 4 and 7.

14. Compare Two Floats


Write a program to compare two floating-point numbers x and y, and print their relationship as
smaller, larger, or equal.

Input:
Two floating-point numbers x and y , separated by a space, are given in a single line.

Output:
For the given two floating-point numbers x and y , print:
●​ 𝑥 < 𝑦: 𝐼𝑓 𝑥 𝑖𝑠 𝑙𝑒𝑠𝑠 𝑡ℎ𝑎𝑛 𝑦.
●​ 𝑥 > 𝑦: 𝐼𝑓 𝑥 𝑖𝑠 𝑔𝑟𝑒𝑎𝑡𝑒𝑟 𝑡ℎ𝑎𝑛 𝑦.
●​ 𝑥 == 𝑦: 𝐼𝑓 𝑥 𝑒𝑞𝑢𝑎𝑙𝑠 𝑦 (𝑢𝑝 𝑡𝑜 𝑠𝑖𝑥 𝑑𝑒𝑐𝑖𝑚𝑎𝑙 𝑝𝑙𝑎𝑐𝑒𝑠).
Constraints:
●​ − 106≤𝑥, 𝑦≤106.
●​ The values of x and y are given with at most six decimal places.

Example:

Input Output

3.14159 x == y
3.14159

10.01 5.5 x>y

1.25 2.5 x<y

15. Check for "world" in the Typed Word


Vasya was typing a message to his friend. He wanted to type the word "world" but was a bit
hasty and started typing a random string of letters. However, Vasya wonders if he typed "world"
correctly, just with some letters missing. If it's possible to delete some letters from the string he
typed to form the word "world", then he successfully typed the word. Your task is to determine if
Vasya managed to say "world".

Input:
●​ The first and only line contains the word s, which Vasya typed. This word consists of
small Latin letters, its length is no less than 1 and no more than 100 letters.

Output:
●​ If Vasya managed to say "world", print "YES", otherwise print "NO".

Example:

1.​ Input: awwrloood


Output: YES
Explanation: Vasya can delete some letters from the typed word to form "world" (e.g.,
"awwrloood" becomes "world").
2.​ Input: wordll
Output: NO
Explanation: In this case, Vasya cannot form the word "world" as the order is
incorrect.
3.​ Input: wrldwo
Output: YES
Explanation: Vasya can delete some letters to form "world".
16. Advanced Calculator
Write a program that reads two integers x,y and an operator op, and then prints the result of the
operation 𝑥 𝑜𝑝 𝑦.

The operator op can be one of these: '+', '-', '*', '/', '^', '%'. The operators represent:

●​ '+' for addition


●​ '-' for subtraction
●​ '*' for multiplication
●​ '/' for division (integer division truncating fractional parts)
●​ '^' for exponentiation (raising xxx to the power yyy)
●​ '%' for modulus (remainder when xxx is divided by yyy)

Input:
●​ The input consists of multiple datasets. Each dataset follows the format: x op y
●​ The input ends with a dataset where the operator 𝑜𝑝 = ′? ′. Your program should stop
processing when it encounters this dataset.

Output:
For each dataset, output the result of the operation on a new line.

Constraints:
●​ 0≤𝑥, 𝑦≤10000
●​ No divisions by zero will be given.

Example :

Input Output

5+7 12
10 - 3 7
3*4 12
15 / 3 5
2^3 8
8%3 2
7?7

17. Convert Time in Seconds to Days, Hours, Minutes, and Seconds


Write a program that reads an integer S (number of seconds) and converts it into the format
days:hours:minutes:seconds.
Input:
An integer S is given in a line, where S represents the number of seconds.

Output:
Print the time in the format days:hours:minutes:seconds. Each value should be printed with no
leading zeroes, and the values should be separated by colons.

Constraints:
●​ 0≤𝑆≤315360000 (𝑇ℎ𝑒 𝑚𝑎𝑥𝑖𝑚𝑢𝑚 𝑣𝑎𝑙𝑢𝑒 𝑜𝑓 𝑆𝑆𝑆 𝑟𝑒𝑝𝑟𝑒𝑠𝑒𝑛𝑡𝑠 10, 000 𝑦𝑒𝑎𝑟𝑠).

Example:

Input Output

100000 1:3:46:40

3600 0:1:0:0

18. Counting Harmed Animals


One day, a farmer had a herd of sheep. He was getting bored and decided to imagine that some
sheep were getting harmed by various actions. Every k-th sheep got a carrot, every l-th sheep got
its wool trimmed, every m-th sheep got its tail tied up, and every n-th sheep got a bell placed
around its neck.

The farmer wonders how many sheep in total were affected after counting d sheep.

Input:
●​ Five integers: k, l, m, n, and d, each on a separate line.
○​ k, l, m, n are the frequencies of each event.
○​ d is the total number of sheep.
Output:
●​ Output the number of sheep that were affected in any way.

Example:

Input Output Explanation


1 12 Every 1st sheep gets a carrot, so all 12 sheep are affected.
2
3
4
12

2 17 The farmer affects sheep based on every 2nd, 3rd, 4th, and 5th sheep,
3 and after removing duplicates, 17 sheep were affected.
4
5
24

19. Find Minimum, Maximum, and Check if All Numbers Are Equal
Vasya is learning about numbers and wants to practice finding the smallest and largest numbers
in a list. He also wants to check if all the numbers in a given list are equal. Help him with these
tasks!

Task:

Given a list of integers, you need to:


1.​ Find the minimum and maximum values in the list.
2.​ Check if all the numbers in the list are the same.

Input:
●​ A list of integers (length of the list will be between 1 and 100).

Output:
●​ First, print the minimum value from the list.
●​ Then, print the maximum value from the list.
●​ Finally, print "YES" if all numbers are the same, otherwise print "NO".

Example:
1.​ Input : 4 5 2 8 3
Output: 2 8 NO
Explanation:
○​ The minimum value is 2 and the maximum value is 8.
○​ The numbers are not all equal, so the output is "NO".
2.​ Input: 7 7 7 7
Output 2:7 7 YES
Explanation:
○​ The minimum and maximum values are both 7.
○​ All numbers are the same, so the output is "YES".
Constraints:
●​ The list will contain at least 1 number.
●​ The numbers are all integers between 1 and 100, inclusive.

20. Palindrome Check


In this problem, you are given a string sss. Your task is to check whether the string sss is a
palindrome. A palindrome is a word, phrase, or sequence of characters that reads the same
backward as forward. For example, "madam" is a palindrome, but "hello" is not.

Input:
●​ A single string sss consisting of lowercase Latin letters.
●​ The length of the string is at most 100.

Output:
●​ Print "YES" if the string is a palindrome.
●​ Otherwise, print "NO".

Constraints:
●​ The string contains only lowercase Latin letters.
●​ The length of the string does not exceed 100 characters.

Example:

Input Output

madam YES

hello NO

Happy Coding!
There are a set of 20 practice problems. The contest will feature 10 questions from here,
similar in type but not identical to the practice set. If you solve these practice problems
properly, you’ll have a strong advantage in the competition.

Contact Us If Needed: www.facebook.com/southasiacomputerclub

You might also like