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

Easy Problem Set

This document contains 6 problems related to if-else statements, arrays, and strings in C++. The problems include determining if a person can afford to travel to a party, distributing coins evenly among cats, counting unique collar combinations for cats, determining if a path is safe to cross based on when minions sleep, judging a soul's fate based on good and bad deeds, and finding the turning point in a string of good and bad deeds. Algorithms are provided for each problem that use concepts like if-else statements, loops, counting occurrences of characters, and tracking minimum values.

Uploaded by

sk262406s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Easy Problem Set

This document contains 6 problems related to if-else statements, arrays, and strings in C++. The problems include determining if a person can afford to travel to a party, distributing coins evenly among cats, counting unique collar combinations for cats, determining if a path is safe to cross based on when minions sleep, judging a soul's fate based on good and bad deeds, and finding the turning point in a string of good and bad deeds. Algorithms are provided for each problem that use concepts like if-else statements, loops, counting occurrences of characters, and tracking minimum values.

Uploaded by

sk262406s
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Easy Problem Set 1

1)if else

New year is approaching fast, Victy wants to join the legendary Tokyo party but before that she needs to go to
Manchuria.
Now Ticket to Manchuria costs P coins, and from Manchuria to Japan it costs Q coins. Victy has X coins in budget.
Victy will also want to spend R coins in party.
Tell if she can afford to go to the New year party in Tokyo.

Input
PQXR

Output
Y (yes)
N (no)

Sample
10 5 7 3
14 6 40 1
Output
N
Y

Algorithm:

f=0;
if(p+q+r <= x)
f=1;
_______________________________________________________________________________________________

Q2)if else

In the Muffin land, there are only two denominations of currency used ,coins of 5 and 7.
Gerald is dying so he wants to distribute his wealth X equally among 3 cats of his.
Now due to old age he has gone senile, so he asks you for help.

Input
T
X
Output
YES
NO

Sample.
5
10
15
27
210
31

Output
NO
YES
NO
YES
NO

Algorithm:

f=0;
if(X%3 == 0)
if(x%5==0 or x%7 == 0)
f=1;
_______________________________________________________________________________________________

Q3)P&C

Old Gerald has 3 cats which are mathematical geniuses and have strange choices when it comes to wearing cat
collars.

1st cat wears even collars .


2nd cat wears odd divisible by 7 or 3 collars.
3rd cat wears odd numbered not divisible by 7 and 3 collars.

They dress up to be a unique combination and don't wear that combo ever again.
(They can wear same collar many times as long as group combo differs).

You’re given an array of size N where Ai is the collar number.


Tell the Number of days in which they will exhaust the set of given collars.

Input
N
a1 a2 a3 ....... an
Output
days

1<=N<=100
1<=A1<=10^6

Sample
3
529
Output
1

Sample
5
53829
Output
2

Algorithm:

separate all unique element using a double loop;


count all even, odd divisible by 7 or 3,odd not divisible by 7 and 3;
multiply all of them.

_______________________________________________________________________________________________

Q3)Array

On new year, Vicky is very excited to go to a party in Tokyo, but she is in Manchuria, treacherous journey lies ahead;

Death's minions dance on the path to party but they sleep for S days on Tth day, that is when she has a chance to
cross.

You are given a path with N cells where each cell has a minion who sleeps at Ai th day (0<i<N) for S days.
(All minions sleep only once).

Assume that it takes 0 days to cross any no. Of cells for Victy.

Being a good buddy, tell Victy if she can cross, if she can tell the time required as well.

Input
T
NS
a1 a2 a3 a5 ........ an

Output
YES time
NO

1<= ai,s <= 364


1<= n <= 100

Sample
4
51
12345
52
22345
73
5 2 4 7 8 9 10
5 100
1 1 3 150 151 177
64
3 4 4 7 12 14

Output
NO
YES 5
NO
YES 177
NO

Explanation :
Case 2:
Victy must wait 2 days for minions to sleep in 1st and 2nd index, after which she goes directly to 2nd
index. Now she can stay at index 2 for at most 2 days (S given). On the third day 3rd indexed minion
goes to sleep as well , so she can move there, on 4th day minion on index 1st and second wake up but
4th sleep so she moves forward, similarly she reaches 5th index as well.
Case 3:
Victy must wait 5 days to let minion at index 1 sleep. While waiting, minion on index 2 sleeps on 2nd
day and wakes up on 5th day. Now this minion will not sleep for another year ruining the chance of
Victy to go to the party.

Algorithm:

f=1;
Loop in array till (n-1)
diff = arr[i+1]-arr[i]
if(diff<0 or diff > S)
f=0,break;
if(f)
print(YES,a[n-1]);
else
print(NO);

_______________________________________________________________________________________________

Q5)String

Gerald ,now dead, arrives in purgatory. Cato is busy so he tells you to judge in his place.

You're given a string of deeds of size N. There three types of deeds Good G, Bad B and Neutral N.

Rule is strange:
if no. of continuous bad deeds after a no. continuous good deed exceeds then Gerald is bound to hell
otherwise heaven it is.
Neutral deeds do not break the continuity.

Input
T (no. of test cases)
N (string length)
S (string)

Output
HL for hell
HN for heaven

T<=200
0<N<500

Sample
3
5
GGGBG
10
GNGNBBGBNB
9
GNGBBGNGG

Output
HN
HL
HN

Algorithm :

g=0,ans=HN
Loop in string
If(ch == N)
Continue;
If(ch == G)
g++;
else If(ch==B)
g--;
If(g<0)
ans=HL,break;
_______________________________________________________________________________________________

Q 6)Array

Gerald on hearing his fate in the afterlife asks you the point in his life which was the turning point.

Just like before you are given a string of G,B,N indicating good, bad and Neutral.

If t is the Turning point, then


| countG[0,t] - countB(t,n-1] | is min over all i.

countG counts all the occurrence of G from [0,t] similarly countB counts occurrences of B from (t,n-1].
|x| represents the absolute value of x.
Output is t.

Input
T
N
S

Output
t

T<=100
N<=10^5
1<=i<=N

Sample
2
5
GGGBB
7
GGGGG

Sample Output
2
1

Algorithm :
min = INT_MAX,p = 0
B = count total number of B;
loop i in arr
if(arr[i] == ‘G’)
G++
if(arr[i] == ‘B’)
B--

if(abs(G-B) < min)


min = abs(G-B)
p = i+1

cout << p << endl;

7)

_______________________________________________________________________________________________
Aditya Narayan

You might also like