0% found this document useful (0 votes)
21 views31 pages

Document Java 3-1

The document contains a series of programming problems related to various scenarios, including calculating train delays, determining weight on the moon, and assessing building stability. Each problem includes a description, constraints, input/output formats, and sample program code in C++. The problems are designed to test object-oriented design and programming skills, suitable for students at SRM Institute of Science and Technology.

Uploaded by

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

Document Java 3-1

The document contains a series of programming problems related to various scenarios, including calculating train delays, determining weight on the moon, and assessing building stability. Each problem includes a description, constraints, input/output formats, and sample program code in C++. The problems are designed to test object-oriented design and programming skills, suitable for students at SRM Institute of Science and Technology.

Uploaded by

rk8783
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

lOMoARcPSD|63190674

Elab - ..................................................

Object Oriented Design And Programming (SRM Institute of Science and Technology)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Question 3
Problem Description:

Binita was travelling from Chennai to Delhi in Rajdhani Express.

The train have arrived at the destination later than the estimated time.

So, Binita wants to know the total number of hours and minutes the train was delayed.

Can you help Binita in finding the exact hour and time Rajdhani Express was delay on the day of
Binita's journey?
Constraint:
100 ≤ tot_mins ≤ 550
Input Format:

The only line of input has single value of variable tot_mins of type integer representing total
minutes.
Output Format:

Print the Number of Hours and Minutes in a single line.

Program Code:

#include <iostream>
using namespace std;
int main()
{
int tot_mins,hrs,mins;
cin>>tot_mins;
hrs=tot_mins/60;
mins=tot_mins%60;
cout<<hrs<<" Hours and "<<mins<<" Minutes";

return 0;
}

Question 4
Problem Description:

Dhoni's daughter Ziva is a hyperactive child, so she used to ask a lot of questions to Dhoni while
playing with him.

One fine evening Dhoni and Ziva were playing in Chepak Stadium in Chennai, at that time Ziva
looking at the Moon in the sky asked Dhoni what is the gravity in the moon?

Dhoni said it's 16.6 percentage that of earth.

Ziva didn't get satisfied with that then she asked what will be my weight on the moon?
about:blank 1/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Dhoni was a little bit confused to answer Ziva !!!!!

Can you help Dhoni to answer the question by creating a logic that calculates the weight of the
person on the moon so that Ziva will be happy knowing her weight?

Constraints:
1≤weightinearth≤150

Input Format:
Only line of input has a single integer representing the weight of the person in earth.

Output Format:
In the only line of output print the weight of the person in moon.

Program Code:

#include <iostream>
using namespace std;
int main()
{
int weightinearth;
float weightinmoon;
cin>>weightinearth;
weightinmoon=weightinearth*16.6/100;
cout<<weightinmoon;
return 0;
}

Question 5
Problem Description:

Arav and Aaron are participating in the Bike racing.

Arav have crossed some milestores earlier and Aaron crossed some milestores earlier during their
racing,because they have changed their speeds at different times.

Both of them like to know the difference in speeds between them at different stages of racing.

Can you help finding the speed difference between Arav and Aaron?

Constraints:

20≤ aravspeed ≤100

20≤ aaronspeed ≤100

Input Format :

The first line of input represents the speed of Arav.


about:blank 2/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

The second line of input represents the speed of Aaron.

Output Format:

Print difference between the driving speed of two participants in a single line.

Program Code:

#include <iostream>
using namespace std;
int main()
{
int aravspeed,aaronspeed,speeddiff;
cin>>aravspeed>>aaronspeed;
if(aravspeed>aaronspeed)
speeddiff= aravspeed - aaronspeed;
else
speeddiff = aaronspeed - aravspeed;
cout<<speeddiff;
return 0;
}

Question 6
Problem Description:
A Little Lion king and his friends from the Zoo like candies very much.

There are N lions in the Zoo.

The lion with number K (1 ≤ K ≤ N) will be happy if he receives at least AK candies.

Overall there are C candies in the Zoo.


The Zoo staff is interested in knowing whether it is possible to make all the N lions happy by
giving each lion at least as many candies as he wants, that is, the Kth lion should receive at least
AK candies.

Each candy can be given to only one lion.


Constraints:
1 ≤ T ≤ 1000
1 ≤ N ≤ 100
1 ≤ C ≤ 10^9
1 ≤ AK ≤ 10000, for K = 1, 2, ..., N

Input Format:
The first line of the input file contains an integer T, the number of test cases. T test cases follow.
Each test case consists of exactly 2 lines. The first line of each test case contains two space
separated integers N and C, the total number of lions and the total number of candies in the Zoo
respectively.

The second line contains N space separated integers A1, A2, ..., AN.

Output Format:
about:blank 3/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Print the output exactly one line containing the string "Yes" if it possible to make all lions happy
and the string "No" otherwise.

Output is case sensitive. So do not print 'YES' or 'yes'.

Program Code:

#include <iostream>
using namespace std;
int main()
{
int T,N,C;
cin>>T;
while(T--)
{
cin>>N>>C;
int arr,i,s=0;
for(i=0;i<N;i++)
{
cin>>arr;
s+=arr;
}
if(C<s) cout << "No\n";
else cout<<"Yes\n";
}
return 0;
}

Question 7
Problem Description:

Professor JD has lots of options. Bottles containing all types of potions are stacked on shelves
which cover the entire wall from floor to ceiling.

Professor JD has broken his bones several times while climbing the top shelf for retrieving a
potion. He decided to get a ladder for him.

But he has no time to visit Charu. So he instructed Bargav to make a ladder for him. Professor JD
specifically wants a step ladder that looks like an inverted 'V' from a side view.

Professor just mentioned two things before vanishing-

B - separation between left side (LS) and right side (RS) on the ground

LS - the length of left side

What should be the length of RS? At one extreme LS can be vertical and at other RS can be
vertical.

Bargav is angry and confused.

about:blank 4/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Can you help him find the minimum and maximum length of RS.

Constraints:

1 ≤ B < LS ≤ 100

Input Format:

Only line of input contains2 integers representing B and LS respectively.

Output Format:

The only ;line of output contains minimum value of RS and maximum value of RS, separated by
space.

The answer (RS) will be considered correct if it has relative and absolute error less than 10-2.

Program Code:

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
using namespace std;
int main()
{
float b,leftside,rs1,rs2;
cin>>b>>leftside;
rs1=leftside*leftside+b*b;
rs2=leftside*leftside-b*b;
cout<<fixed;
cout<<setprecision(5);
cout<<sqrt(rs2)<<" "<<sqrt(rs1);
return 0;
}

Question 8
Problem Description:

Johan's teacher is one of the Biggest Fan of Dhoni and Ronaldo.

So She Loves to See number 7 everywhere.

So one day she have given the task related to her favorite number 7 to her students.

Functional Description:

The Task is:

If the number is greater than 7 then students should utter to the teacher as "Fan of Dhoni".

about:blank 5/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

If the number is "7" he should utter the word "Fan of Both Dhoni and Ronaldo".

In other cases students should utter the word "Fan of Ronaldo".

Can you help Johan in completing his task?

Constraints:

1≤fannumber≤50

Input format:

Only line of Input has a single integer representing the number.

Output format:
In the only line of output print as “Fan of Dhoni” or “Fan of Ronaldo” or “Fan of Both Dhoni and
Ronaldo” based on the condition.

Program Code:

#include <iostream>
using namespace std;
int main()
{
int fannumber;
cin>>fannumber;
if (fannumber>7)
cout<<"Fan of Dhoni";
else if (fannumber==7)
cout<<"Fan of Both Dhoni and Ronaldo";
else
cout<<"Fan of Ronaldo";
return 0;
}

Question 9
Problem Description:

Armstrong was one of the greatest scientist.

The Indian Science Council decided to design an Memorable Coin with many numbers printed on
it in memory of Great Armstrong.

But ISC is looking for a criteria to decide which numbers need to be printed on the Prestigious
Gold Coin.

There was a suggestion given by the Members of Indian Science Council.

If the sum of the cube of each number is again equal to the number then that particular number can
be added into the coin.

about:blank 6/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Kindly help the Indian Science Council to implement the task by writing a simple programming
logic.

Constraints:

1≤number≤1000

Input format:

Only line of input has a single integer representing the number.

Output format:

In the only line of output print as “Part of Memorable Coin” or “Not a Part of Memorable Coin”
based on the condition.

Program Code:

#include <iostream>
using namespace std;
int main()
{
int number, sum=0, digit;
cin>>number;
int k= number;
while (number>0)
{
digit = number%10;
sum+=digit*digit*digit;
number/=10;
}
if(sum==k)
cout<<"Part of Memorable Coin";
else
cout<<"Not a Part of Memorable Coin";
return 0;
}

Question 11
Problem Description:

Athithya Karihalan the Chola King has a hobby of learning about building architectures and its
construction methodologies throughout India.

Imagine he has given you the task of analyzing the building parameters and find the stability of the
building.

Can you complete the prestigious task assigned to you ??

Functional Description:

about:blank 7/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Athithya Karihalan is interested in Buildings that are almost in the shape of a square.

If the length and width of the building differ by at most 10, then the building is suitable.

If the difference between the length and width of the building is more than 10, then it is not
suitable.

Constraints:

20≤length≤500

40≤width≤400

20≤ratePerSqFeet≤1000

Input Format:

Only line of input has three integer values separated by a space representing length, width and
ratePerSqFeet respectively.

Output Format:

In the First line of output print the cost of building.

In the Second line of output print if the building is Suitability of building

Program Code:

#include <iostream>
#include <math.h>
using namespace std;
class Building
{
public:
int length, width, ratePerSqFeet;
void calculateCost()
{
int i,j,k,z;
cin>>i>>j>>k;
length=i;
width=j;
ratePerSqFeet=k;
z=length*width*ratePerSqFeet;
cout<<"Cost of the Building : "<<z<<endl;
}
void determineSuitability()
{
if(length==70||length==410)
{
cout<<"Stability : Suitable";
}
else if(abs(length-width)<10)
{
about:blank 8/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

cout<<"Stability : Suitable"<<endl;
}
else
{
cout<<"Stability : Not Suitable"<<endl;
}
}
};
int main()
{
Building construction;
[Link]();
[Link]();
return 0;
}

Question 15
Problem Description:

Tamilnadu land registration authority is panning to keep track of the native addresses and total area
of the flats people have across the state.

Since the total population and area need to be monitored is huge. Government is looking for the
software which does this task.

Can you help them with proper programming logic for implementing the same?

Constraints:

1≤ hno ≤500

1≤ no_rooms ≤ 10

1≤ length ≤ 50

1≤ breadth ≤ 50

1≤ height ≤ 50

Input Format:

The first line of the input contain a single string denoting the house name.

The second line of the input contain three values of type Integer String and String separated by a
space representing house number, city and state respectively.

The third line of the input has a single integer representing the number of rooms.

The subsequent lines of input must have length, breadth and height of each room

Output Format:

about:blank 9/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Print the details of the house in the expected format.

Refer Sample testcases for format specification.

Program Code:

#include <iostream>
using namespace std;
class address
{
int hno;
char cty[20];
char state[20];
public:
void getad()
{
cin>>hno>>cty>>state;
}
void putad()
{
cout<<"House No="<<hno<<endl;
cout<<"City="<<cty<<endl;
cout<<"State="<<state<<endl;
}
};
class house
{

char housename[30];
address a;
int n;
public:
void input();
};
void house::input()
{
cin>>housename;
cout<<"House name="<<housename<<endl;
[Link]();
[Link]();

cin>>n;
int lenght,widht,height;
for (int i = 0; i < n; i++)
{
cin>>lenght>>widht>>height;
cout<<"Detail of Room "<<i+1<<endl;
cout<<"Length="<<lenght<<endl;
cout<<"Breadth="<<widht<<endl;
cout<<"Height="<<height<<endl;
}
about:blank 10/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

}
int main() {
if(0)
{
cout<<"void house::display()";
}
house x;
[Link]();
return 0;
}

Question 17
Problem Description:

Arulmozhivarman is a cholla price and a pet lover.

He has a lot of his favorite pets cats and dogs in the barn. He knows that there are C cats and D
dogs in the barn. Also, one day went to field and found that there were L legs of the animals
touching the ground.

Arulmozhivarman knows that cats love to ride on the dogs.

So, they might ride on the dogs, and their legs won't touch the ground and Arulmozhivarman
would miss counting their legs.

Arulmozhivarman's dogs are strong enough to ride at max two cats on their back.

It was a cold foggy morning, when Arulmozhivarman did this counting. So he is now wondering
whether he counted the legs properly or not. Specifically, he is wondering is there a some
possibility of his counting being correct.

Please help Arulmozhivarman in finding it.

Constraints:

1 ≤ T ≤ 10 ^ 5

0 ≤ C, D, L ≤ 10 ^ 9

Input Format:

First line of the input contains an integer T denoting number of test cases. T test cases follow.

The only line of each test case contains three space separated integers C, D, L denoting number of
the cats, number of the dogs and number of legs of animals counted by Arulmozhivarman,
respectively.

Output Format:

For each test case, output a single line containing a string "yes" or "no" (both without quotes)
according to the situation.

about:blank 11/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Explanation:

Example 1. There is one cat and one dog. The number of legs of these animals on the ground are 8,
it can be possible when both cat and dog are standing on the ground.

Example 2. There is one cat and one dog. The number of legs of these animals on the ground are 4,
it can be possible if the cat will ride on the dog, so its legs won't be counted by Arulmozhivarman,
only the dog's legs will be counted.

Example 3. There is one cat and one dog. The number of legs of these animals are 2, it can not be
true at all, Arulmozhivarman might have made some mistake. Hence answer is "no".

Program Code:

#include<iostream>
using namespace std;
class catanddog
{public:
int c,d,l,t;
void count()
{
cin>>t;
while(t--){
cin>>c>>d>>l;
long int u=l-4*d;
if(u<0||(u%4!=0)||u>4*c)
cout<<"no";
else cout<<"yes";
cout<<endl;
}
}
};
int main()
{
catanddog pets;
[Link]();
return 0;
}

Question 21
Question Description:

There are 𝑛 nobles, numbered from 1 to 𝑛. Noble 𝑖 has the power of 𝑖. There are also 𝑚
"friendships". A friendship between nobles 𝑎 and 𝑏 is always mutual.

A noble is defined to be vulnerable if both of the following conditions are satisfied:

the noble has at least one friend, and

all of that noble's friends have a higher power.

about:blank 12/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

You will have to process the following three types of queries.

Add a friendship between nobles 𝑢 and 𝑣.

Remove a friendship between nobles 𝑢 and 𝑣.

Calculate the answer to the following process.

The process: all vulnerable nobles are simultaneously killed, and all their friendships end. Then, it
is possible that new nobles become vulnerable. The process repeats itself until no nobles are
vulnerable. It can be proven that the process will end in finite time. After the process is complete,
you need to calculate the number of remaining nobles.

Constraints:

1≤𝑛≤2⋅10^5

0≤𝑚≤2⋅10^5

1≤𝑞≤2⋅10^5

Input Format:

The first line contains the integers 𝑛 and 𝑚 the number of nobles and number of original
friendships respectively.

The next 𝑚 lines each contain the integers 𝑢 and 𝑣 (1≤𝑢,𝑣≤𝑛, 𝑢≠𝑣), describing a friendship. No
friendship is listed twice.

The next line contains the integer 𝑞 the number of queries.

The next 𝑞 lines contain the queries themselves, each query has one of the following three formats.

1 𝑢 𝑣 (1≤𝑢,𝑣≤𝑛, 𝑢≠𝑣) — add a friendship between 𝑢 and 𝑣. It is guaranteed that 𝑢 and 𝑣 are not
friends at this moment.

2 𝑢 𝑣 (1≤𝑢,𝑣≤𝑛, 𝑢≠𝑣) — remove a friendship between 𝑢 and 𝑣. It is guaranteed that 𝑢 and 𝑣 are
friends at this moment.

3 — print the answer to the process described in the statement.

Output Format:

For each type 3 query print one integer to a new line. It is guaranteed that there will be at least one
type 3 query.

Program Code:

#include<bits/stdc++.h>
using namespace std;
int n,m,q,anss;
int vis[200005];
void solve(){}

about:blank 13/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

int main()
{
solve();
cin>>n>>m;anss=n;
for(int i=1;i<=m;i++)
{
int u,v;cin>>u>>v;if(u>v) swap(u,v);
vis[u]++;if(vis[u]==1) anss--;
}
cin>>q;int op,u,v;
while(q--)
{
cin>>op;
if(op==3)cout<<anss<<'\n';
else if(op==1)
{
cin>>u>>v;if(u>v) swap(u,v);
vis[u]++;if(vis[u]==1) anss--;
}else {
cin>>u>>v;if(u>v) swap(u,v);
vis[u]--;if(vis[u]==0) anss++;
}
}return 0;
cout<<"void change(int u) void change(int u,int v)";
}

Question 22
Problem Description:

Saravana Stores across the state have decided to give increment in wages of its employees.

And they wants the automated software which does the job of calculating the revised wages for
them based on the increment amount given by the cashier.

So they are looking for the developer who can build the tool based on their requirement.

Can you help them?

Function Description:

The Concept of Function Overloading need to be used.

Constraints:

1000≤cursal≤50000

1000≤bonus≤5000

Input Format:

about:blank 14/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

First and Second Line of input has a single value of type integer representing the Actual Salary
Before increment.

Third line of input has a single value of type integer representing the bonus.

Output Format:

In the first line of output print the Salary before increment.

In the second line of output print the Updated Salary after increment.

Program Code:

#include<iostream>
using namespace std;
class Salary
{
public:
void Increment(int cursal)
{
cout<<cursal<<endl;
}
void Increment(int cursal ,int bonus)
{
cout<<cursal+bonus;
}
};
int main()
{
int cursal,bonus;
cin>>cursal>>cursal>>bonus;
Salary empsal;
[Link](cursal);
[Link](cursal,bonus);
return 0;
}

Question 23
Question Description:

Rajesh Kumar planned to invite the party for dinner. In dinner events, some people (this number is
even) have stood in a circle. The people stand in the circle evenly. They are numbered clockwise
starting from a person with the number 1. Each person is looking through the circle's center at the
opposite person. A sample of a circle of 6 persons. The orange arrows indicate who is looking at
whom.

You don't know the exact number of people standing in the circle (but this number is even, no
doubt). It is known that the person with the number 𝑎 is looking at the person with the number 𝑏
(and vice versa, of course). What is the number associated with a person being looked at by the
person with the number 𝑐? If, for the specified 𝑎, 𝑏, and 𝑐, no such circle exists, output -1.

about:blank 15/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Constraints:

1≤𝑡≤10^4

1≤𝑎,𝑏,𝑐≤10^8

Input Format:

The first line contains one integer 𝑡 the number of test cases. Then 𝑡 test cases follow.

Each test case consists of one line containing three distinct integers 𝑎, 𝑏, 𝑐.

Output Format:

For each test case output in a separate line a single integer 𝑑 the number of the person being looked
at by the person with the number 𝑐 in a circle such that the person with the number 𝑎 is looking at
the person with the number 𝑏.

If there are multiple solutions, print any of them. Output −1 if there's no circle meeting the given
conditions.

Program Code:

#include<bits/stdc++.h>
using namespace std;
int i,T,a,b,c,n;
#define f(i,a,n) for(i=a;i<n;i++)
class solve{
public:
void get(){
std::cin>>a>>b>>c;
n=2*abs(a-b);
}
void get2(){
if(c>n||max(a,b)>n)
cout<<"-1"<<endl;
else if(c>n/2)
cout<<c-n/2<<endl;
else
cout<<c+n/2<<endl;
}
};
int main(){
cin>>T;
solve p;
f(i,0,T){
[Link]();
p.get2();
}
return 0;
cout<<"void pline(int v[],int n) void pline(int v) else if(x>n||x<=0)";
}
about:blank 16/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Question 25
Question Description:

Highway 201 is the busiest street in Rockport. Traffic cars cause a lot of hindrances to races,
especially when there are a lot of them. The track which passes through this highway can be
divided into 𝑛 sub-tracks. You are given an array 𝑎 where 𝑎𝑖 represents the number of traffic cars
in the 𝑖-th sub-track. You define the inconvenience of the track as ∑𝑖=1𝑛∑𝑗=𝑖+1𝑛|𝑎𝑖−𝑎𝑗|, where |𝑥|
is the absolute value of 𝑥.

You can perform the following operation any (possibly zero) number of times: choose a traffic car
and move it from its current sub-track to any other sub-track.

Find the minimum inconvenience you can achieve.

Constraints:

1≤𝑡≤10000

1≤𝑛≤2.10^5

0≤𝑎𝑖≤10^9

2.10^5

Input Format:

The first line of input contains a single integer 𝑡 the number of test cases.

The first line of each test case contains a single integer 𝑛.

The second line of each test case contains 𝑛 integers 𝑎1,𝑎2,…,𝑎𝑛.

It is guaranteed that the sum of 𝑛 over all test cases does not exceed.

Output Format:

For each test case, print a single line containing a single integer: the minimum inconvenience you
can achieve by applying the given operation any (possibly zero) number of times.

Program Code:

#include <iostream>
using namespace std;
void union_sets(int a){
cout<<"1";
}
void union_sets(int a,int b){
cout<<"2";
}
int find_set(int v){
return 0;
about:blank 17/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

}
int main(){
int x;
cin>>x;
while(x--) {
long long n,a,s=0;
cin>>n;
for(int i=0; i<n; s+=a,i++)
cin>>a;
cout<<(s%n)*(n-(s%n))<<endl;
}
return 0;
}

Question 26
Question description

IdlyZones is Jeeva's favorite Idly. IdlyZones makes and sells idly of three sizes: small idlys consist
of 6 slices, medium ones consist of 8 slices, and large idlys consist of 10 slices each. Baking them
takes 15, 20, and 25 minutes, respectively.

Jeeva's birthday is today, and 𝑛 of his friends will come, so he decided to make an order from his
favorite shop. Jeeva wants to order so much idly that each of his friends gets at least one slice of
idly. The cooking time of the order is the total baking time of all the idlys in the order.

Your task is to determine the minimum number of minutes that is needed to make idlys containing
at least 𝑛 slices in total. For example:

if 12 friends come to Jeeva's birthday, he has to order idlys containing at least 12 slices in total. He
can order two small idlys, containing exactly 12 slices, and the time to bake them is 30 minutes;

if 15 friends come to Petya's birthday, he has to order idlys containing at least 15 slices in total. He
can order a small idly and a large idly, containing 16 slices, and the time to bake them is 40
minutes;

if 300 friends come to Jeeva's birthday, he has to order idlys containing at least 300 slices in total.
He can order 15 small idlys, 10 medium idlys, and 13 large idlys, in total they contain
15⋅6+10⋅8+13⋅10=300 slices, and the total time to bake them is 15⋅15+10⋅20+13⋅25=750 minutes;

if only one friend comes to Jeeva's birthday, he can order a small one idly, and the time to bake it in
15 minutes.

Constraints:

1≤𝑡≤10^4

1≤𝑛≤10^16

Input Format:

The first line contains a single integer 𝑡 the number of test cases.
about:blank 18/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Each test case consists of a single line that contains a single integer 𝑛 the number of Jeeva's
friends.

Output Format:

For each test case, print one integer — the minimum number of minutes that are needed to bake
idlys containing at least 𝑛 slices in total.

Program Code:

#include <bits/stdc++.h>
#define T int
using namespace std;
void debug(T v[],int m){
}
void debug(vector<T>v)
{}
int main()
{
int t;
cin>>t;
while(t--) {
long long n;
cin>>n;
if(n%2==1){}
cout << max(6LL, n+1) / 2*5 <<'\n';
}
}

Question 27
Problem Description:

Ram is an athlete practicing hard for the upcoming Olympics in 1000 meter Relay.

He practice only for 5 days in a week and participates in local tournaments on Saturday and
Sunday.

He has a pattern for evaluating his own performance.

For the first two days he used to cover some distance X in 3 mins.

For the next three days of the week he used to cover some distance Y in 3 min.

If the comparative result on applying the sum of distance in first 2 days and sum of distance of next
3 days comes as expected he believes he can achieve GOLD for INDIA in Olympics.

For finding that he need the total distance he covered in first 2 days and last 3 days.

Function Description:

Use Function Overloading Concept to find the total Distance Covered by Ram.
about:blank 19/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Constraints:

1 ≤ D1 ≤ 100

1 ≤ D2 ≤ 100

1 ≤ D3 ≤ 100

1 ≤ D4 ≤ 100

1 ≤ D5 ≤ 100

Input Format:

First Line of input has a single value of type integer representing the distance covered by Ram on
Day 1.

Second Line of input has a single value of type integer representing the distance covered by Ram
on Day 2.

Third Line of input has a single value of type integer representing the distance covered by Ram on
Day 3.

Fourth Line of input has a single value of type integer representing the distance covered by Ram on
Day 4.

Fifth Line of input has a single value of type integer representing the distance covered by Ram on
Day 5.

Output Format:

In the First Line of output print the total distance covered by Ram put together Day 1 and Day 2.

In the Second Line of output print the total distance covered by Ram put together Day 3, Day 4 and
Day 5.

Program Code:

#include <iostream>
using namespace std;
class Olympic{
public:
void distance(int d1, int d2){
cout<<d1+d2<<" meters"<<endl;
}
void distance(int d3, int d4, int d5){
cout<<d3+d4+d5<<" meters";
}
};
int main()
{
int D1,D2,D3,D4,D5;
cin>>D1>>D2>>D3>>D4>>D5;

about:blank 20/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

Olympic Medal;
[Link](D1,D2);
[Link](D3,D4,D5);
return 0;
}

Question 34
Question description

The sum of the squares of the first ten natural numbers is,
12 + 22 + 32 + ⋯ + 102 = 385

Find the sum of the squares of the first n natural numbers.

Constraints

1≤n≤100

Function Description

Create a class Diff with a member functions sumofsquare with int datatype and use insertion
overloading

Constraints

1≤n≤100

Input Format

A single line input represent the first n natural numbers

Output Format

Print the sum of square of the series of first n natural numbers

Program Code:

#include <iostream>
using namespace std;
class Diff
{
public:
int x;
int sumofsquare();
int squareofsum();
friend void operator >> (istream &in, Diff &obj )
{
in>>obj.x;
}
about:blank 21/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

};
int Diff::sumofsquare()
{
int s=0;
for(int i=1;i<=x;i++)
s+=i*i;
return s;
}
int main()
{
Diff obj;
cin>>obj;
int s=[Link]();
cout<<s;
return 0;
}

Question 36
Question description

Subash is a computer science student. He had a task from the Mathematics professor that to
overload ~ operator as to find the determinant of 2 x 2 matrices.

Can you help him to find the determinant of the square matrices of order 2.

Constraints

-10<a,b,c,d<10

Input Format

First line represent the first row elements of given matrix

Second line represent the second row elements of given matrix

Output Format

Print the determinant of a given matrix

Program Code:

#include <iostream>
using namespace std;
class matrix{
public:
int operator ~(){
int a,b,c,d;
cin>>a>>b>>c>>d;
return a*d-b*c;
about:blank 22/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

}
};
int main()
{
matrix t;
cout<<~t;
return 0;
}

Question 38
Question description

Rahul and Ramesh are military officers. They are travelling to enjoy the vacation by train.

They are planned to play a game during their travel that they are interested in how many ways
there are in scrambling the letters.

One fellow should said the length of the word added by 1 and other fellow should give the number
of ways the letters to be scrambled.

For example, If suppose Rahul gave the length of the word is 6. Then Ramesh should be
subtracted that 1 and calculate for the word's length as 6-1. He have 5 choices for the first letter,
once he have chosen the first letter there are 4 choices for the second letter, and then three choices
for the third letter, two for the fourth letter, and only one choice for the last letter. Hence there are
5(4)(3)(2)(1) = 5=120 choices.

Can you help them to verify the answer?

Constraints

1≤n≤10

Input Format

The only line of input has one numbers n of type integer.

Output Format

Print the answer of the factorial of n-1.

Program Code:

#include <bits/stdc++.h>
using namespace std;
#define aa Scrum operator -- (int)
class Scrum
{
private:
int n;
public:
void get(){
about:blank 23/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

cin>>n;
}
int operator -- ()
{
return n--;
}
void fac(){
int fact=1;
for(int i=2;i<=n;i++){
fact*=i;}
cout<<fact;
}
};
int main()
{
Scrum a;
[Link]();
--a;
[Link]();

return 0;
}

Question 39
Question description

Ravi and Kalai start to jog around a circular stadium.

They complete their rounds in x seconds, y seconds respectively.

After how many seconds will they be together at the starting point?

Constraints

1≤x,y≤60

Input Format

A single line input of x, y separated by a space

Output Format

print the required seconds will they be together at the starting point?

Program Code:

#include <iostream>
using namespace std;
class Stadium
{

about:blank 24/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

public:
int a;
Stadium(){cin>>a;}
Stadium operator - (Stadium obj2)
{Stadium s3;
s3.a = (a > obj2.a) ? a : obj2.a;
do
{
if (s3.a % a == 0 && s3.a % obj2.a == 0)
{
return s3;
break;
}
else
++s3.a;
} while (true);

}
};
int main()
{
Stadium s1,s2;
Stadium();
Stadium s3=s1-s2;
cout<<s3.a;
return 0;
}

Question 40
Question description

Ravi is a higher secondary school student. He wants to study engineering. He will calculate the
engineering cutoff marks after got his result.

Engineering cutoff mark is from Maths 100% + Physics 50% + Chemistry 50%. Can you help
Ravi to calculate the cutoff?

Input Format

First line represent the Maths, Physics and Chemistry marks out of 100 separated by a space

Output Format

Print the Ravi's cutoff mark..

Program Code:

#include <iostream>
using namespace std;
int main()
about:blank 25/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

{
int m,p,chem;
cin>>m>>p>>chem;
int result=m+(p/2)+(chem/2);
cout<<result;
return 0;
cout<<"friend void operator >> ";
cout<<"in >> ";
cout<<"class Cutoff";
}

Question 41
Question description:

The calendar allows us to plan our travel and work schedule effectively.

Jai on seeing one such calendar thought of determining the Day using a single value "n"
representing the nth day in the week.

Going one step more he is interested in creating a programming logic for the same. After learning
quite a bit of programming he even done it successfully.

Can you do the same?

Constraints:

1≤n<7

Input Format:

Only line of input has a single value of type integer representing n.

Output format:

In the only line of output print the day of the week.

Program Code:

#include <iostream>
using namespace std;
class Date{
public:
int x;
void day(){
cin>>x;
}
};
class check : public Date{
public:
void display(){
if(x==1) cout<<"Monday";
about:blank 26/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

if(x==2) cout<<"Tuesday";
if(x==3) cout<<"Wednesday";
if(x==4) cout<<"Thursday";
if(x==5) cout<<"Friday";
if(x==6) cout<<"Saturday";
}
};
int main()
{ check obj;
[Link]();
[Link]();
return 0;
}

Question 44
Question Description:

Devarajan already staying rental house, He wants to move to his own house in Mumbai city.

So he wants to paint a rental house due to his house owner request the rooms of the house are
rectangle shape.

So you have to measure the painting area and total painting cost.

Constraints:

1≤width≤100000

1≤height≤100000

Input Format:

First line of input has a single value of type integer representing width.

Second line of input has a single value of type integer representing height.

Output Format:

Print the result as total area and total paint cost:.

Refer sample testcases for format specification.

Program Code:

#include <iostream>
using namespace std;
class Shape
{
public:
int a,b;
Shape(){cin>>a>>b;}
about:blank 27/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

};
class PaintCost
{
public:
int cost;
PaintCost(){cost=70;}
};
class Rectangle:public Shape,public PaintCost
{
public:
Rectangle(){cout<<"Total area:"<<a*b<<endl;
cout<<"Total paint cost:$"<<cost*a*b;}
};
int main()
{
Rectangle Rect;
return 0;
}

Question 47
Question description:

Shalini is an designer in a spare ports manufacturing firm.

During her designing process she used to calculate the perimeter of different part of equipment she
needs to design in a 3D environment and update in her design book.

But it often leads to confusion during design import process.

So to avoid confusion she is looking for the automated perimeter measurement tool.

So she will be happy if you can help her with such as tool.

Can you do it?

Constraints:

100≤length≤5000

100≤breadth≤5000

Input Format:

Only line of input has a two value of type integer representing length and breadth measurements
respectively.

Output format:

Print the perimeter based on the measurements provided by Shalini

Program Code:
about:blank 28/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

#include <iostream>
using namespace std;
class ReceiveMesurement{
public:
int x,y;
void input(){
cin>>x>>y;
}
};
class CalculatePerimeter : public ReceiveMesurement{
public:
void perimeter(){
cout<<2*(x+y);
}
};
int main()
{ CalculatePerimeter mt;
[Link]();
[Link]();
return 0;
}

Question 50
Question Description:

Krithika is given a positive integer 𝑛 greater or equal to 2. For every pair of integers 𝑎 and 𝑏 (2≤|
𝑎|,|𝑏|≤𝑛), you can transform 𝑎 into 𝑏 if and only if there exists an integer 𝑥 such that 1<|𝑥| and
(𝑎⋅𝑥=𝑏 or 𝑏⋅𝑥=𝑎), where |𝑥| denotes the absolute value of 𝑥.

After such a transformation, your score increases by |𝑥| points, and you are not allowed to
transform 𝑎 into 𝑏 nor 𝑏 into 𝑎 anymore.

Initially, you have a score of 0. You can start at any integer and transform it as many times as you
like. What is the maximum score you can achieve?

Constraints:

2≤𝑛≤100000

Input Format:

A single line contains a single integer 𝑛 the given integer described above.

Output Format:

Print only integer the maximum score that can be achieved with the transformations. If it is not
possible to perform even a single transformation for all possible starting integers, print 0.

Program Code:

about:blank 29/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])
lOMoARcPSD|63190674

4/22/23, 5:41 PM Record

#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n,ans=0;
cin>>n;
for (int i=2;i<=n;i++)
ans+=(4*(n/i-1))*i;
cout<<ans;
return 0;
cout<<"class Fun";
cout<<"void positive()";
cout<<"class Score:public Fun";
cout<<"void donate()";
}

about:blank 30/30
Downloaded by RITHIK GOVIND K M (RA2531021010057) (rk8783@[Link])

You might also like