Professional Documents
Culture Documents
21BCS4853 Saurav Sirsat
21BCS4853 Saurav Sirsat
21BCS4853 Saurav Sirsat
Assignment-1
Student Name: Saurav Sirsat UID: 21BCS4853
Branch: CSE Section/Group: FL-602-B
Semester: 6 th Date of Performance: 24/05/24
Subject Name: IT Skills
Q1 MoEngage noticed that some users are not aware of the practice page on
CodeChef, and some others are not aware of the rated contests on CodeChef.
So, MoEngage wants to send an email to the users depending on which of the
following groups they fall into:
If the user has never submitted on the practice page then send an email with
the text:
https://www.codechef.com/practice
If the user has submitted on the practice page, but never participated in a
contest then send an email with the text:
https://www.codechef.com/contests
If the user has submitted on the practice page as well as participated in a
contest then send an email with the text: https://discuss.codechef.com so
that they may discuss with other members of the community. Help
MoEngage by writing a program that takes as input two integers 𝐴A
and 𝐵B where:
𝐴=1A=1 if the user has submitted on the practice page and 00 otherwise.
𝐵=1B=1 if the user has participated in a contest and 00 otherwise. Output
the appropriate link to be displayed in the email.
def main():
# Read the input values
A, B = map(int, input().split())
Q2. There is a kingdom in land of fire and ice known as westros. The
kingdom is ruled by mad king Amen Targareyan. Further more Westros is
divided into two territories. One territory known as ice because it is always
snowing and other Fire beacuse of volcano near by area. There is rebellion to
overthrow the mad king to bring peace to Westros. There is a secret attack on
red fort by rebellion force lead by Luke Skywalker. There is snitch in
rebellion force. He trades the secret attack plan to mad king. However mad
king has superpower to sense disturbance in the force. He sends out his best
knights to scout the rebellion force. He got to know that rebel force outmatch
city guards one to hundred. Moreover he came to know that Luke is last jedi
who can detroy him.In order to win this battle against rebels, the mad king
decided to use N common folks as soldiers. He select a bunch of people from a
territory and train them .Now king can only select odd number of people
from land of fire and from land of ice in one go. He cannot select bunch of
people consecutively from either territory.In how may ways the mad king
could assemble his army to battle against rebel forces ? Note: The number of
people in each territory is infinite
dp[0] = 1; // Base case: one way to assemble an army of size 0 (do nothing)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int
T;
cin >> T;
return 0;
}
Q3. Given an input string (s) and a pattern (p), implement wildcard pattern
matching with support for '?' and '*' where:
'?' Matches any single character.
'*' Matches any sequence of characters (including the empty sequence). The
matching should cover the entire input string (not partial).
class Solution {
public boolean isMatch(String s, String p) {
int m = s.length();
int n = p.length();
return dp[m][n];
}
}
Q4. A machine recycles scrap bottles, the size of the bottle is categorised into
types. For 𝑛n number of bottles you have to calculate the number of bottles in
each category type. Size to category table:-
BOTTLE SIZE: | 1,2 - TYPE 1 | 3,4 - TYPE 2 | 5,6 - TYPE 3
while (T--) {
int N;
cin >> N;
vector<int> bottles(N);
for (int i = 0; i < N; i++) {
cin >> bottles[i];
}
return 0;
}
Q5. You are being given a number N . (1<=N<=1000). You have to print the
sum of digits of that particular number.
int main() {
int T; cin
>> T;
cin.ignore();
while (T--) {
string number;
getline(cin, number);
cout << sumOfDigits(number) << endl;
}
return 0;
}
Q6. Chef knows about two languages spoken in Chefland, but he is not
proficient in any of them. The first language contains lowercase English
letters between 'a' and 'm' inclusive and the second language contains only
uppercase English letters between 'N' and 'Z' inclusive.
Due to Chef's limited vocabulary, he sometimes mixes the languages when
forming a sentence — each word of Chef's sentence contains only characters
from one of the languages, but different words may come from different
languages.
You are given a sentence as a sequence of 𝐾K words 𝑆1,𝑆2,…,𝑆𝐾S1,S2,…,SK.
Determine whether it could be a sentence formed by Chef, i.e. if it contains
only the characters from the two given languages and each word contains
only characters from a single language.
Code and Output
#include <iostream>
#include <vector> #include
<string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
cin.ignore(); // Ignore the newline character after the number of test cases
while (T--) {
int K; cin
>> K;
bool validSentence = true;
return 0;
}
Q7. Given a string s representing a valid expression, implement a basic
calculator to evaluate it, and return the result of the evaluation.
Note: You are not allowed to use any built-in function which evaluates strings
as mathematical expressions, such as eval().
if (isdigit(c)) {
number = number * 10 + (c - '0');
} else if (c == '+' || c == '-') {
result += sign * number; number
= 0; sign = (c == '+') ? 1 : -1;
} else if (c == '(') {
nums.push(result);
ops.push(sign);
result = 0;
sign = 1; } else if (c == ')')
{ result += sign *
number;
number = 0;
return result;
}
};
Q8. A digit string is good if the digits (0-indexed) at even indices are even and
the digits at odd indices are prime (2, 3, 5, or 7).
For example, "2582" is good because the digits (2 and 8) at even positions are
even and the digits (5 and 2) at odd positions are prime.
However, "3245" is not good because 3 is at an even index but is not even.
Given an integer n, return the total number of good digit strings of length n.
Since the answer may be large, return it modulo 109 + 7.
A digit string is a string consisting of digits 0 through 9 that may contain
leading zeros.
// Calculate the total number of valid combinations for even indices long
long evenTotal = power(evenChoices, (n + 1) / 2, MOD);
return static_cast<int>(result);
}
private:
// Function to calculate (base^exponent) % MOD efficiently using binary
exponentiation
long long power(long long base, long long exponent, int MOD) {
long long result = 1; while (exponent > 0) { if
(exponent % 2 == 1) {
result = (result * base) % MOD;
}
base = (base * base) % MOD;
exponent /= 2;
}
return result;
}
};