Professional Documents
Culture Documents
Sample input 2:
15 50
Sample output 2:
5 10
Skill testing
Amar’s team is assigned with a project that deals with the digital signals. He is aware that the digital
signals will be represented as arrays. He wants to test his team with respect to their strength in
arrays. As part of the skill testing the task is as follows:
You are given an array of integers of size N.
Consider all its contiguous subarrays of length k and find the maximum sum.
Do this for all k from 1 to the length of the input array.
Write a program to evaluate the task done by the kids.
Input format:
The first line contains a single integer denotes the size of the array N.
The second line contains N-space separated integer that corresponds to the values of the array.
Output format:
The output consists of N-space separated integer that corresponds to the values of the array.
Sample input 1:
5
-1 2 1 3 -2
Sample output 1:
34653
Explanation:
For inputArray=[-1,2,1,3,-2], the output should be [3,2,1,0,0].
The contiguous subarray
Of k=1,each subarray will have 1 element, the sub-array with maximum sum is [3]. So result[0]=3.
Of k=2,each subarray will have 2 elements, the sub-array with maximum sum is [1,3]. So result[1]=4.
Of k=3,each subarray will have 3 elements, the sub-array with maximum sum is [2,1,3]. So
result[2]=6.
Of k=4,each subarray will have 4 elements, the sub-array with maximum sum is [-1,2,1,3]. So
result[4]=5.
Of k=5,each subarray will have 5 elements, the sub-array with maximum sum is [-1,2,1,3,-2]. So
result[5]=3.
Sample input 2:
5
2 3 2 -2 3
Sample output 2:
35768
Anuska’s instruction
Anuska has created a robot that will take instructions and work accordingly. Due to budget problem,
she has set the memory low. To overcome that, she has to encode the instruction. Given the
instruction s, count the consecutive characters and each character will be followed by its frequency.
For example, if the instruction is “aaaabb”, the encoded instruction is “a4b2”.
Note:
If the frequency is one, the count need not be printed.
Input format:
The first input is a string that denotes the instruction, s.
Output format:
Output is a string that denotes the encoded string.
Sample input 1:
aaaabb
Sample output 1:
a4b2
sample input 2:
sggvvvgss
sample output 2:
sg2v3gs2
Team Assessment
The Team Leader of Testing team of XYZ company decided to assess the team members by
organising a programming event. So he gave the team a task.
The task is given an array of size , find the number of distinct elements in the array and print them in
ascending order. Those members who answer, will get some reward.
Write a program to help the Team Leader to evaluate the solution of the team members.
Input format:
The first line contains s single integer that denotes the size of the array, N.
The second line contains N space separated integer values of the array.
Output format:
The first line is an integer that denotes the number of the distinct elements in the array.
The second line is a series of integers separated by space that denotes the distinct elements
Sample input 1:
5
12121
Sample output 1:
2
12
Sample input 2:
5
145 25 21 25 36
Sample output 2:
4
21 25 36 145
Summer Vacation Game
In summer vacation time, the students of ABC school went for a team outing. A game was conducted
by the Incharge for the student so that they can enjoy. So he told them to take one integer N and
arrange the digits of the integer in incremental order from right to left. Help students by writing a
code.
Input format:
The first line contains s single integer that denotes the given number, N.
Output format:
The output is an integer in which the digits of N are arranged in incremental order from right to left.
Sample input 1:
231
Sample output 1:
321
Picnic Event
As part of the picnic events, the families from ABC apartment plan to organize same games for their
kids so that they can learn something during leisure time also. The task is as follows:
Given a string S, find the string which has only the distinct character in S. the characters should be
presented in the descending order of its occurrence. If the occurrence count of two characters is
same, then the order for those two characters should be the same as its is in the input string.
Input Format:
The input is a string that denotes the S.
Note:
The String is case-sensitive.
Output format:
The output is a string that denotes the modified string.
Sample input 1:
HelloWorld
Sample output 1:
loHeWrd
sample input 2:
Entertainment
Sample Output 2:
nteEraim
Mock 2
Practical Exam Preparation
Vel is a first year computer science student. The next day he is having his practical’s lab exam. His
sister (Priya) is working in atop IT firm. To test vel, she gives him a problem to solve. The problem is
to find the N-th special number, given he value of N. she also defines a number to be special, if it’s
units place digit only consist of 0,1,2,3,4 or 5.
Write a program to help vel.
Input format:
First input is an integer that denotes the N value.
Output format:
Output is an integer that denotes the N-th special number.
Sample input 1:
5
Sample output 1
4
Explanation:
Here N=5
The first 5 special numbers are 0,1,2,3 and 4. So the output is 4.
Sample input 2:
60
Sample output 2:
95
Explanation:
Here N=60.
The first 60 special numbers are as follows:
0,1,2,3,4,5,10,11,12,13,14,15,20,21,22,23,24,25,30,31,32,33,34,35,40,41,42,43,44,45,50,51,52,53,54
,55,60,61,62,63,64,65,70,71,72,73,74,75,80,81,82,83,84,85,90,91,92,93,94 and 95
So the output is 95.
Sai’s Programming Skills
Sai is doing his 5th grade in VIBGYOR International School. He has already started to do programming.
Priya, being a programming geeks, tests her son’s knowledge by asking him to code for her
requirement. The requirement is as follows:
Given two arrays A and B each containing N numbers, choose exactly one number from A and
exactly one number from B such that the index of the two chosen numbers is not same and the sum
of the 2 chosen values is minimum. Formally, if you choose ith element from A whose value is x and
jth element from B whose value is y, you need to minimize the value of (x+y) such that i is not equal
to j.
Help Sai in writing the program.
Input format:
First line of the input is an integer that denotes the N value, size of the array.
Second line of the input is a series of n integers separated by a space that denotes the array values
of A.
Third line of the input is a series of n integers separated by a space that denotes the array values of
B.
Assume:
All the elements in each array are distinct.
Output format:
Output is an integer that denotes the minimum value as per the requirement.
Sample input 1:
5
12345
54321
Sample output 1:
2
Explanation:
Here x is 1 (the first element of A) and y is also 1 the last element of B). their sum is 2.
Sample input 2:
6
2548696
4 5 6 9 8 10
Sample output 2:
7
Explanation
Here x is 2(the first element of A) at index 0 and y is 4 at index 0. Since the index of j is also the same,
we choose the next smallest element which is 5 at index 1.
Bangles gift
Vel bought 2 bangles for his elder sister Priya, as a birthday gift. Before presenting the gift, vel
challenges his sister to answer his question blindfolded. He places both the bangles on the table and
asks priya to answer two questions:
1. Are the two bangles intersecting or touching or not touching?
2. What is the distance between the centers of the bangles?
To answer these questions, Vel gives the centers c1(x1,y1) and c2(x2,y2) and radius r1 and r2 of the
bangles.
Now write a program to help priya to answer her brother’s questions.
Input format:
First line of the input consists of two integers separated by a space which corresponds to x1 and y1
values, respectively.
Second line of the input consists of two integers separated by a space which corresponds to x2 and
y2 values, respectively.
Third line of the input consists of two integers separated by a space which corresponds to r1 and r2
values, respectively.
Output format:
First line of the output is a string, “intersects” or “Touches” or “Do not Touch”.
Second line of the output is a float value which corresponds to the distance between the two centers
of the bangles, rounded off to 2 decimal points.
Sample input 1:
34
14 18
58
Sample output 1:
Do not Touch
17.80
Sample input 2:
34
46
45
Sample output 2:
Intersects
2.24
Choclolate box
Priya returned to India from the onsite trip to Singapore. She bought lots of chocolates for his son sai
and younger brother vel. The chocolate box is square shaped and contains identical compartments.
Each compartment contains several number of chocolates. Now comes the fight between sai and vel
for the chocolates. To stop the fight, priya gives a condition to both of them that, the compartments
in the upper triangular part of the box are for sai and that of the lower triangular part is for vel, and
the compartments in the main diagonal will be shared by priya and her husband.
Now help sai and vel to find how many chocolates did each get, by writing a program.
Note:
In this problem, upper triangle consists of elements above the main diagonal, and the lower triangle
consists of elements below the main diagonal.
Input format:
First input is an integer that denotes the N value, size of the box. The range of n is [1 – 15], both
inclusive.
Next N lines of the input consists of N integers separated by space in each line, that denotes the
number of chocolates in each compartment.
Output format:
Output is two integers separated by a space that denotes the number of chocolates for sai and
number of chocolates for vel respectively.
Note:
If N=1, there is no upper triangle and lower triangle. The single element present corresponds to the
main diagonal.
Sample input 1:
4
1234
8596
1 2 3 15
5716
Sample output 1:
39 24
Reorder the students
Sai is doing his 5th grade in VIBGYOR international school. He is the most intelligent student in his
class, and his class teacher has made him the representative for his class. Now its play time. There
are n students in his class and each student is given a card that has a number written in it. Sai, being
the representative, has to reorder those kids as per the order given to him.
Help sai in reordering the kids, by writing a program.
Input format:
First input is an integer that denotes the n value, the number of students.
Second input is a series of n integers separated by a space that denotes the numbers given to each
student.
Third input is a series of n integers separated by a space that denotes the array which contains the
order in which the students have to be reordered.
Assume:
The elements of the 2nd array are unique and always greater than or equal to 0 and less than n.
Output format:
Output is a series of n integers separated by a space that denotes the reordered array.
Sample input 1:
3
14 15 16
120
Sample output 1:
16 14 15
Explanation:
The first array: 16 14 15
The order array: 1 2 0
Here the first element 16 should be moved to index 1.
The second element 14 should be moved to index 2.
The third element 15 should be moved to index 0.
So, after moving, the final order is 16 14 15
Sample input 2:
5
12345
12034
Sample output 2:
31245
Sliding number
nd
Priya’s son sai is doing his 2 grade. He started learning about number. To test his intelligence, priya
asks him to solve a problem. The problem is to find the number of sliding numbers within a given
range. A number is called sliding number if all adjacent digits have an absolute difference of 1.
For e.g. ‘432’ is a sliding number while 542 is not.
Write a program to help sai to find the number of sliding number in range [m,n](both inclusive)
Input format:
First input is an integer that denotes the m value.
Second input is an integer that denotes the n value.
Assume:
n>M>=10
output format:
output is an integer that denotes the number of sliding numbers.
Sample input 1:
10
25
Sample output 1:
4
Explanation:
Sliding numbers are 10 12 21 23
Sample input 2:
10
16
Sample output 2:
2
Mock 3
Boat travel
You’re travelling in boat, the water currents sometimes they slow you down. You need to calculate
the time to reach. Knowing the boat speed and wate current speed.
A boat moves at a constant speed of x dmph without water flow. the water flow also affects the
speed of the boat.
Given the ideal boat speed and the water flow speed, write a program to find the time required to
reach a given distance.
Input format: :
First LIne of the input contains a single integer value that denotes the ideal boat speed in kmph.
Second Line of the input contains a single integer value that denotes the water flow speed in
kmph(+ve when it favors the boat and -ve when it disfavours.
Third Line of the input contains a single integer value that denotes the distance to be convered in
km.
Output format::
A single integer value that denotes the time taken to reach the given distance.
Assume::
The time taken will always be an integer.
sample input 1::
20
5
100
sample output 1::
4
sample input 2::
25
-5
100
Bigger Number
Suriya loves playing with numbers. He comes up with a new game idea of creating a greater number
than the given number by changing exactly one digit. Now he has to find the number of ways in
which this is possible. Help Suriya to develop a program to find the number of ways to obtain a
bigger number.
input format::
Input contains a single integer that denotes the given number.
output format::
the output contains a single integer that denotes the number of ways.
sample input 1::
10
sample output1 ::
17
Input format::
First Line of the input contains a single integer that denotes the size of the array n.
Second line consists of n space seperated integer array values. The input array values will always be
a permutation of numbers from 1 to n.
output format::
the output consists of n space separated integers that denote the output array values.
sample input 1:
4
1234
Sample output 1:
1423
--------------------------------------------------------------------------------------------------------------------------------------
Diagonal Difference:
Roshan just found out that matrix can be implemented using 2d arrays. He is good in programming.
So he tries to develop a program to do his math homework. Help Roshan to write a program to do
his math homework.
In his math homework, a square matrix of size N is given. He needs to calculate the absolute
difference between the sums of the diagonals.
Help Roshan by writing a program.
Input Format:
The first line contains a single integer denotes the size of the matrix, N.
The next N lines denote the matrix’s rows, with each line containing N space-separated integers
describing the columns.
Output format:
Print the absolute difference between the two sums of the matrix’s diagonals as a a single integer.
sample input 1:
3
11 2 4
456
10 8 -12
Sample Output 1:
15
Explanations:
The primary diagonal elements are:
11 5 -2
Sum across the primary diagonal: 11+5-12=4
--------------------------------------------------------------------------------------------------------------------------------------
Power Pairs:
Your friend challenges you to play a game, in which you have to find the number of Power pairs in
the series of numbers. A Power pair is formed when a number b is divisible by another number a
that occurs before the number b in the given sequence. you can easily win the challenge by
developing a program to find it.
Input format:
first line of the input contains a single integer that denotes the size of the array n.
second line consists of n space separated integers that denote the array values.
output format:
The output consists a single integer that denotes the number of power pairs in the given sequence.
sample input 1:
3
132
sample output 1:
2
Explanation:
for sequence=[1 3 2]
the sorted pairs are:(1,3),(1,2).
so output should be 2.
--------------------------------------------------------------------------------------------------------------------------------------
Main1:
COST FOR SPIRAL BINDING
Your final year project papers has to be spiraled (spiral binding). The cost for spiraling depends on
the thickness of the spiral. If thickness is <= 1 cnm
the cost is Rs.50, if thickness>1cm and <=2cm, the cost is Rs.100. If thickness>2cm and <=3cm, the
cost is Rs.150. For each 1cm increase in spiral thickness, it costs Rs.50 additionally. A total of 2-
sheets will give a thickness of 1mm. Given the number of sheets, write a program to find the cost of
spiral.
Input format:
first line consists of a single integer that denotes the number of sheets to be spiraled.
output format:
output is an integer that denotes the cost for spiralling.
sample input 1:
225
sample output 1:
100
sample input 2:
488
sample output 2:
150
explanation:
for sample input 1→ 225 sheets has to be spiraled. 225 sheets will make around 1.125cm, since it is
less than 2 cm and greater than 1 cm, it costs Rs. 100.
for sample input 2 → 488 sheets has to be spiraled, 488 sheets will make around 2.44cm, since it is
less than 3cm and greater than 2cm, it costs Rs.150.
--------------------------------------------------------------------------------------------------------------------------------------
Free Fall
A boy drops a ball from the top of the building of height h. Write a program to find the velocity at
which it hits the ground.
Formula:
Equations of motion, v2=u2+2gh.
Note:
Assume Air in the atmosphere is not affecting the speed. Take g=9.8m/s2.
input format:
first input is an integer that denotes the height of the building in meteres.
output format:
Output is a double vlaue that denotes the velocity of the ball at which it hits the ground.(Rounded
off to two decimal places)
sample input 1:
45
sample output 1:
29.70
sample input 2:
15
sample output 2:
17.15
Explanation:
For sample input 1 → Height of the building - 45m. From equations of motion formula we can find
the velocity at which the ball will hit the ground. At the instant when the ball is dropped, its initial
velocity is u=0,, so v2=0+2*9.8*45=√882=29.70
--------------------------------------------------------------------------------------------------------------------------------------
Parallel Resistors:
In electronic circuits, resistors are used to reduce current flow and adjust signal levels. Resistors can
be connected either in series or in parallel. Given N resistors which are connected in parallel and
their respective resistance values, write a program to find the total resistance.
Formula:
1/R=1/R1+1/R2+1/R3+...+1/Rn
Input format:
first input is an integer that denotes the number of resistors N.
second line consists of series of n integers separated by a space that denotes the resistance values.
output format:
output is a double value that denotes the total resistance.(Rounded off to two decimal places)
sample input 1:
2
12 12
sample output 1:
6.00
sample input 2:
5
12345
sample output 2:
0.44
explanations:
for sample input 1-->2 resistors are connected parallely and their resistance value is 12 and 12. The
formula to find total resistance for the parallel connection is 1/R=1/R1+1/R2+1/R3+...+1/Rn.
the net resistance is, 1/R=1/12+1/12=2/12=⅙. therefore to find R, take reciprocal.
the total resistance is R=6.00
--------------------------------------------------------------------------------------------------------------------------------------
AWESOME CHARACTERS
Raghu has twin sons and they are studying in 8th grade. To test their knowledge, he gave them a fun
task to play with. The task is to find the awesome characters. Two characters x and y are said to be
awesome characters if absolute difference between their ascii values produce a character that is an
uppercase alphabet. Given x and y values as inputs, write a program tofind whether the characters
are awesome characters or not and also print the difference in the next line.
Input format:
first line consists of a two space separated characters that denotes x and y.
output format:
output is of two lines.
1) print “Awesome Characters’ if absolute difference between their ascii values produce a
character that is a uppercase alphabet, else print “Normal Characters”.
2) also print the absolute difference between their ascii values.
sample input 1:
AZ
sample output 1:
Normal Characters
25
sample input 1:
v!
sample output 2:
Awesome Characters
85
Explanation:
For sample input 1-->the ascii value for A is 65 and Z is 90. Their absolute difference is 25
and their difference in ascii values did not produce an uppercase alphabet. So A and Z are
normal characters.
For sample input 1-->the ascii value for v is 118 and ! is 33. Their absolute difference is
85and their difference in ascii values produces an uppercase alphabet. So v and ! are
Awesomel characters.
---------------------------------------------------------------------------------------------------------------------------
COST OF TABLE
A rectangular table has 4 semi-circle on all the 4 edges and the semicircle portion is cut from
the table. Given the length and width of the rectangular table in cm, radius of the semicircle,
find the area of the table and if the area is greater than 20000 sqcm, the table will be
painted, else the table will be given a wooden finish.
Given the cost for painting and wooden finish per sq.cm, write a program to find the total
cost of the table.
Note:
Area of semi-circle=(3.14*r*r)/2
input format:
first line consists of s single integer that denotes the length of the table.
second line consists of a single integer that denotes the width of the table.
third line consists of a single integer that denotes the radius of the semi-circle.
next line consists of a single double value that denotes the cost for painting per sq cm.
last line consists of single double value that denotes the cost for wooden finish per sq cm.
output format:
output is a double vlaue that denotes the total cost of the table. (Rounded off to two
decimal places)
sample input 1::
15
17
3
102.3
142.2
sample output 1:
28223.86
sample input 2:
100
70
20
12
11
sample output 2:
53856.00
---------------------------------------------------------------------------------------------------------------------------
7 SEGMENT LED DISPLAY
A seven segment display (SSD_, or seven segment indicator, is a form of electrnic device for
displaying decimal in digital format. kTow single digi numbers a and b are given as inputs,
initially, the number a is displayed in the 7 segment LED display. write a pprogram to
determine how many segments has to be alered (either urn on or turn off) to change from a
to b.
Input ormat:
first input is an integer that denotes the first number a
second input is an integer that denotes the second number b
output format:
output is an integer that denotes the number of segments to be changed.
sample input 1:
6
1
sample output 1:
6
sample input 2:
4
5
sample output 2:
3
explanation:
For sample input 1→ first number 6 is displayed in 7 segment display., it takes 6 segments
(a,f,e,d,c,g) to display. Number 1 takes 2 segments (b,c) to display. So no change from 6 to 1
(a,f,g,e,d) has to be turned off and (b) has to be turned on. Hence a total of 6 segments
needs to be changed.
For sample input 2→ first number 4 is displayed in 7 segment display, it takes 4 segments
(f,g,b,e) to display Number 5 takes 5 segments (a,f,g,c,d) to display. so to change from 4 to
(b) has to be turned of and (a,d) has to he turned on,(f,g and c) are already turned on, so
they need not be considered. Hence a total of 3 segments (b-->off and a,d-->on) needs to be
changed.
---------------------------------------------------------------------------------------------------------------------------
LUCKY CHAIR
Rohan and his friends were playing a game. there are n number of chairs arranged both row
wise and column wise. Each chair is moved with number at the back. Each person has to find
the lucky chair. The chair which is present in the row with maximum sum and column with
the minimum sum is the lucky chair. Given a matrix a, write a program to find the a[x][y],
where x is the row with max sum and y is the column with min sum.
Note:
consider 0 based index for rows and columns. if two rows or columns have same maximum
sum or minimum sum take the first occurring row or column.
input format:
first line consists of single integer that denotes the row size of the matrix.
second line consists of a single integer that denotes the column size of the matrix.
next line consists of series of integers separated by a space that denotes the array values.
output format:
output is an integer that denotes the a[x][y] value.
sample input 1:
3
3
123
456
789
sample output 1:
7
sample input 2:
4
2
10 20
41 25
15 136
145 2
sample output 2:
136
--------------------------------------------------------------------------------------------------------------------------
TOTAL RUNS
Given the total runs, number of boudaries and sixes made by players of the cricket team,
write a program to calculate the total percentage of runs made by the players by running
between the wickets.
input format:
first line contains a single integer that denotes the total runs.
second line contains a single integer that denotes the number of boundaries
third line contains a single integer that denotes the number of sixes.
output format:
output contains a single integer denoting the the total percentage of runs made by running
between the wickets.
sample input 1:
100
8
5
sample output 1:
38
sample input 2:
125
5
8
sample output 2:
45
explanation:
for sample input 1→ total runs is 100, he scored 8 boundaries and 5 sizes. so the total runs
made by running between wickets is 100-(8*4+5*6)=38
total percentage of runs he made by running between the wickets is = (38/100)*100=38
---------------------------------------------------------------------------------------------------------------------
For sample input 2: there are 7 elements in the array 1 25 48 46 35 125 191
First element: 1- has 1 odd digig 1
Second elemet: 25- has 1 odd digit 5
Last element : 191- has 3 odd digit 1 9 1
All other elements has even number of odd digits 35 125 or no odd digts at all 48 46, so its is
considered as normal array. Also there are only 3 values that satisfies the condition.
--------------------------------------------------------------------------------------------------------------------------------------
Magic number
Sherlock holmes is trying to solve a puzzle that leads him to his next destination. He has a note that
contains two integers that specify the lower bound and the upper bound and says to find the
smallest number divisible by all the numbers in that interval. Help shelock by developing a program
for him.
Note 1: both the upper bound and the lower bound are inclusive.
Note 2: always upper bound>=lower bound.
Input format:
The first line of the input contains single integer that denotes the lower bound
The second line of the input contains a single integer that denotes the upper bound.
Output format:
Output is an integer that denotes the smallest number divisible by all the numbers in the interval
between upper bound and the lower bound.
Sample input 1:
2
6
Sample output 1:
60
Explanation:
60 is the smallest number that is divisible by all 2 3 4 5 6
Sample input 2:
4
10
Sample output 2:
2520
Explanation:
2520 is the smallest number that is divisible by all 4 5 6 7 8 9 10
------------------------------------------------------------------------------------------------------------------------------------
The sticks
On summer vacation, jennier and her sister used to have ice-candy everyday. Jennifer’s sister used
to collect those ice sticks.
Now she has n ice sticks of different lengths. Jennifer’s sister wanted to play a game with those
sticks. So Jennifer suggested a game, that is, game of triangle.
In this game, there are n sticks of different lengths and one has to find the number of triangles that
can be constructed using any three of these sticks.
Constraints:
· The sum of the lengths of any two sides of a triangle must be greater that the third side.
· Equal triangles that are constructed from different sticks are considered different.
Input format:
First line contains a single integer that denotes the size of the array n.
Second line contains of n space separated integer values of the array that denote the stick lengths.
Output format:
A single integer output that denotes the number of triangles that can be formed.
Sample input 1:
4
3579
Sample output 1:
3
Explanation:
The triangles can be formed sing
3 5 7 – because 3+5>7 and 5+7>3 and 3.7>5
5 7 9 – because 5+7>9 and 7+9>5 and 9+5>7
3 7 9 – because 3+7>9 and 7+9>3 and 9+3>7
And 3 5 9 cannot be used to construct triangle because 3+5<9
-------------------------------------------------------------------------------------------------------------------------------------
Matrix assignment
Ravi is a 6h grade student in ABC school. He had a lecture session on matrix subtraction and an
assignment to be solved.
Given two matrices, find the difference between each elements in the matrices and print the matrix.
If the dimensions of the two matrices are not matching, then print invalid.
Input format:
The first line contains a single integer denotes the row size of the first matrix, m.
The next line contains a single integer denotes the column size of the first matrix, n.
The next m lines denote the matrix’s rows, with each line containing n space-separated integers of
the second matrix.
Output format:
If the dimensions are matching, print m lines that denote the result matrix’s rows, with each line
containing n space separated integers of the difference matrix.
Else print invalid
Sample input 1:
3
2
100
400
033
3
3
123
986
342
Sample output 1:
0 -2 -3
-5 -8 -6
-3 -1 3
--------------------------------------------------------------------------------------------------------------------------------------
Middle element
The middle of the array arr is defined as follows:
If arr contains odd number of element, its middle is the element whose index number is the same
when counting from the beginning of the array and from its end;
If arr contains an even number of elements, its middle is the average of the two elements whose
index numbers when counting from the beginning and from the end of the array differ by one.
When array arr, write a program to find its middle and if it consists of two elements, replace those
elements with the value of middle. Print the resulting array as the answer.
Note:
If the middle produces a floating point result, take its floor value.
Input format:
The first line contains a single integer that denotes the size of the array, n.
The second line consists of n space separated integer values of the array.
Output format:
Output consists of space separated integer values of the result array.
Sample input 1:
5
152 23 7 887 243
Sample output 1:
152 23 887 243
Explanation:
Here the number of elements is odd. So the middle is 7 and the result array is same as the input
array
Sample input 2:
5
11 23 543 342 97
Sample output 2:
11 23 543 342 97
Sample input 3:
6
7 2 2 5 10 7
Sample output 3:
7 2 3 10 7
--------------------------------------------------------------------------------------------------------------------------------------
Find the century
John is an archaeologist, and he wants to categorize the artefacts that he found by their centuries.
He knows their year of origin, now he needs to find their century.
Given a year, write a program to print the century of its origin.
The first century spans from the year 1 up to and including the year 100, the second – from the year
101 up to and including the year 200, and so on.
Input format:
First line of the input contains a single integer that denotes the year of origin.
Output format:
Output is a single integer that denotes the century of origin.
Sample input 1:
1992
Sample output 1:
20
Sample input 2:
1300
Sample output 2:
13
--------------------------------------------------------------------------------------------------------------------------------------
Adult or juvenile
Ram is planning to go on a world tour. Before visiting the countries he wants to verify whether he’s
an adult as per that countries rules. Help him develop a program to check whether he is an adult or
juvenile using his age and the adulthood age in a particular country.
Note that people whose age is the same as the adulthood age are considered adult.
Input format:
The first line contains a single integer that corresponds to the age of ram.
The second line contains a single integer that corresponds to the adulthood age of a particular
country.
Output format:
The first line of the output is a string. Print adult, if ram satisfies the adulthood age, else print
juvenile.
The second line of the output is an integer that denotes the absolute difference between ram’s age
and adulthood age.
Sample input 1:
32
18
Sample output 1:
Adult
14
Sample input 2:
12
16
Sample output 2:
Juvenile
4
--------------------------------------------------------------------------------------------------------------------------------------