cw_questions
cw_questions
R102)
R103)
R104)
R105)
R106)
R107)
R108)
R109)
R110)
R111)
R112)
R113)
R113)
R115)
R114)
R117)
R115)
R119)
R116)
R121)
R117)
Round 2: Code Rush (speed-coding)
R201)
1a)
Write a C++ program to find twin prime numbers within a
specified range. Twin primes are pairs of prime numbers that
differ by exactly 2. For example, (3, 5), (5, 7), and (11, 13) are
twin prime pairs.
Your program should take two integer inputs, 'start' and 'end',
representing the inclusive range within which to search for twin
primes. The program should then identify and display all twin
prime pairs within this range.
1b)
Write a C++ program to decompress text. The compressed
version has a number next to each symbol/letter, representing the
amount of time that symbol should appear.
For example, ‘a2b3’ is the compressed version of ‘aabbb’.
1c)
Write a C++ program that takes in a string that contains a
sentence, checks if the first letter of each subsequent word is the
same as the last letter of the previous word. If the condition is
met, output true, if not, output false. Casing does not matter.
For example, ‘This string gets stuck’ returns TRUE.
2a)
Write a C++ program to implement wildcard pattern
matching. In wildcard matching a string and a pattern are
accepted. If the string and the pattern match it returns true. The
string consists of various alphanumeric values while the pattern
can have alphanumeric values and two special symbols: '?' and
'*'.
'?' matches any single character.
'*' matches by sequence of characters(including empty sequence)
For example, string = "aa" and pattern = "?b" returns false. 'a'
and '?' match however 'a' and 'b' do not match hence returning
false.
2b)
Write a C++ program where a word is randomly selected by the
computer and the user has a limited number of guesses to find
the word selected. Each turn the user guesses one word at a time.
If any letter in the guessed word exists in the computer-selected
word, the computer reveals where in the word the letter/s
has/have appeared.
For example,
Guess the word: _ _ _ _ _
You have 6 guesses.
Your Guess [1]: Water
Guess the word: _ e _ _ _
Your Guess [2]: Cello
Guess the word: _ e l l o
Your Guess [3]: Hello
Guess the word: Hello
Correct!
R202)
1a)
Write a C++ program to guess a number between 1-100. Set a
limited number of guesses. Each wrong guess should display
either ‘higher’ or ‘lower’ depending on the guessed number and
the generated number between 1-100.
1b)
Write a C++ program to reverse every word in a sentence.
For example, ‘I am a boy’ results in, ‘I ma a yob’.
1c)
Write a C++ program to convert every word in a sentence
into its piglatin equivalent. A piglatin text is created by placing
the consonants at the beginning of a word at the end, followed by
‘ay’. If the word begins with a vowel, then ‘yay’ is appended to
the end of the word.
For example, ‘What time is it?’ results in ‘atwhay imetay isyay
ityay?’.
2a)
Write a C++ program to replace numerical values into their
alphabetical names in any given sentence.
For example, ‘I greeted the 107-year-old man’ would result in ‘I
greeted the hundred and seven-year-old man’
2b)
Write a C++ program to solve a sudoku puzzle.
For example,
‘5 3 0 0 7 0 0 0 0
600195000
098000060
800060003
400803001
700020006
060000280
000419005
0 0 0 0 8 0 0 7 9’
Would result in,
‘5 3 4 6 7 8 9 1 2
672195348
198342567
859761423
426853791
713924856
961537284
287419635
3 4 5 2 8 6 1 7 9’.
R203)
1a)
Write a C++ program to find the sum of all even numbers in
a Fibonacci sequence up to a specified limit 'n'. The Fibonacci
sequence is a series of numbers where each number is the sum of
the two preceding ones, typically starting with 0 and 1.
Your program should take an integer input 'n' and calculate the
sum of all even Fibonacci numbers less than or equal to 'n'.
1b)
Write a C++ program to check if a number is an Armstrong
number. An Armstrong number is one whose sum of its own digits
raised to the power number of digits gives the number itself.
For example, 0, 370, 1634 are some Armstrong numbers.
1c)
Write a C++ program to identify whether a number is a
happy number. A happy number is one where the sum of the
squares of the digits eventually equals 1.
For example, 203 is happy because 2² +0² +3² = 13; 1² +3² = 10;
1² +0² = 1
2a)
Write a C++ program to convert an alphabetical number into
its decimal equivalent. An alphabetical number has the digits 0-9
and from 10-35 it is represented by the letters a-z.
For example, '1bza' results in '62182'.
2b)
Write a C++ program to find all the pairs of consecutive
powerful numbers below 1000. A powerful number, also known as
a squarefull number, is a positive whole number n such that for
every prime number p dividing n, p 2 also divides n. Every
powerful number can be written as a 2b 3, where a and b are
positive integers.
For example, (8, 9) are a pair of consecutive powerful numbers.
R204)
1a)
Write a C++ program to check whether a number is a
special palindrome. A special palindrome is one where one halve
of the number appears exactly as it is in the second halve.
For example, '12312' results in a special palindrome whereas
'12321' does not return a special palindrome.
1b)
Write a C++ program to analyse a given string to see
whether alliteration occurs in it.
For example, 'A sweet sickening melody' results in True.
1c)
Write a C++ program to find all abundant numbers between
a given range 'm' to 'n'. An abundant is a number that is smaller
than the sum of its aliquot parts (proper divisors).
For example, 12 is an abundant number as its aliquot parts result
in 16.
2a)
Write a C++ program to find the optimal manner of storage
if given a set of weights of items and their respective value. How
many different items can be stored in a bag of defined weight
such that the bag has the highest possible value.
2b)
Write a C++ program to find the optimal solution to place 'n'
number of queens on a nxn board such that no two queens attack
each other.
For example, 4 results in True and displays the diagram:
OQOO
OOOQ
QOOO
OOQO
R205)
1a)
Write a C++ program to capitalise the first letter of each
word in a given sentence.
For example, 'everyOne rAN away' results in 'Everyone Ran Away'.
1b)
Write a C++ program to find if a given input is a magic
number. A magic number is one whose sum of digits eventually
equals 1.
For example, 55 is a magic number.
1c)
Write a C++ program to find if a given number is near prime.
A near prime is a number that has exactly 4 factors including
itself.
2a)
Write a C++ program to check if a number 'n' is weird. A
weird number is an abundant number that is not semiperfect; in
other words, n is weird if the sum of its divisors is greater than n,
but n is not equal to the sum of any subset of its divisors.
2b)
Write a C++ program to encrypt a given phrase using the
vigenère cipher. Vigenere Cipher is a method of encrypting
alphabetic text. It uses a simple form of polyalphabetic
substitution. A polyalphabetic cipher is any cipher based on
substitution, using multiple substitution alphabets. The program
accepts the phrase to be encrypted and the key to be used, and
returns the encrypted text.
For example, if 'attack at dawn' and 'lemon' are the phrase and
the key respectively, 'lxfopvefrnhr' will be the output.
R206)
1a)
Write a C++ program to identify a perfect number. A perfect
number is a whole number that is equal to the sum of all its
factors except itself.
For example 6 is a perfect number.
1b)
Write a C++ program to display the binary equivalent of any
decimal number entered.
1c)
Write a C++ program to find the greatest common factor for
any two numbers 'n' and 'm'.
2a)
Write a C++ program to alphabetically sort a given set of 'n'
numbers.
2b)
Write a C++ program to identify a Kaprekar number. Take a
positive whole number n that has d number of digits. Take the
square of n and separate the result into two pieces: a right-hand
piece that has d digits and a left-hand piece that has either d or
d–1 digits. Add these two pieces together. If the result is n, then n
is a Kaprekar number.
For example, 9 results in True.
R207)
1a)
Write a C++ program to convert a given decimal number
into its hexadecimal form.
1b)
Write a C++ program to find if a number is a niven number.
A Niven number is any whole number that is divisible by the sum
of its digits.
For example, 126 results in True.
1c)
Write a C++ program to exchange the first and last letter of
each word. Keep the format as it was.
For example, 'New Delhi is the capital of India' results in 'Wen
Ielhd si eht lapitac fo Andii'.
2a)
Write a C++ program to find whether a prime number is a
chen prime. A chen prime is a prime number 'n' such that n+2 is
either prime or the product of two primes.
For example, 2 is a chen prime.
2b)
Write a C++ program to decrypt a Caesar cipher given no
key. The Caesar cipher is a type of substitution cipher, where each
letter in the plaintext is replaced by a letter some fixed number of
positions down the alphabet. The Caesar cipher uses a fixed key,
which is the number of positions by which the letters are shifted.
We can solve a Caesar cipher by bruteforcing all the possible
solutions, that is, by using all the keys from 1 to 25.
For example, 'Se tgsk it Puykvn' will result in a total of 25 different
iterations of the possible solutions.
R301A)
Write a C++ program to create a Pascal's triangle without using a
loop, that is via recursion.
Input: 4
Output:
1
11
121
1331
14641
R301B)
Input: 5
Output:
1
11
121
1331
14641
1 5 10 10 5 1
Input: 3
Output:
1
11
121
1331
R302A)
Write a C++ program to identify whether 2 given words are
anagrams of each other.
Input:
Wares
Wears
Output:
True
R302B)
Input:
Persecution
Prosecution
Output:
False
Input:
Wares
Wears
Output:
True
R303A)
Write a C++ program to find the least common divisor for 'n'
different numbers.
Input:
3
7
15
21
Output:
105
R303B)
Input:
5
876
543
321
999
555
Output:
30255617
Input:
3
7
15
21
Output:
105
R304A)
Write a C++ program to find the greatest factor of a number
excluding itself.
Input:
1737
Output:
579
R304B)
Input:
162791
Output:
1
Input:
1737
Output:
579
R305A)
Write a C++ program to decrypt a Caesar cipher given its key.
Input:
hdakt iwxh itmi
15
Output:
solve this text
R305B)
Input:
rnkud sghr sdws
25
Output:
solve this text
Input:
hdakt iwxh itmi
15
Output:
solve this text
R306A)
Write a C++ program to find a special prime number. A special
prime number is one whose prime factors add up to form a prime
number. A prime factor of a number are those factors that are
prime in nature
Input:
759
Output:
True
R306B)
Input:
885
Output:
True
Input:
441
Output:
False