Programming Geek
Rated 4.7/5 based on 1446 reviews  ### CodeVita 2013 Questions : Set2

Isotope Fusion
(Complex Problem)
Problem Statement:
Scientists recently found a new element X, which can have different isotopes upto an atomic value of 199. Speciality of element X is that when two atoms fuse they produce energy multiple of their atomic value and forms an atom with atomic value of their multiple modulus 199.
For Eg:
If atom1 with value 56 and atom2 with value 61 fuse.
They produce energy of 3416 KJ (56 * 61)
Resulting atom will have atomic value (56*61) mod 199 = 33
Scientists created a nuclear reactor to create energy by this method. Everyday they get several atoms of X from supplier in a particular sequence. Since this element highly radioactive they cant risk by changing its sequence. So each atom can fuse only with another atom nearby. Nevertheless scientists can choose order of fusion thereby maximizing total energy produced.
Now, for given sequence of atomic values, output maximum energy that can be produced.
Example
If sequence of atoms are
56,61, 2
Then they can produce 3416KJ by fusing 56&61 which results in an atom of value 33. Then they can fuse 33 and 2 to get energy of 66KJ. So total energy generated is 3482.
But if they cleverly choose to fuse atoms 61 & 2 first then they generate 122 KJ with a resulting atom of value 122. Then if they fuse 122 and 56, they can generate 6832 KJ. So total energy is 6954.
Hence Maximum energy that can be generated from this sequence is 6954.

Input Format
Input starts with a number specifying number of inputs(n) followed by n space separated integers specifying atomic values of n atoms.
 Line 1 N,where N is the number of atoms in the sequence to be fused. Line 2 a1 a2 a3 .... an where ai -> Atomic value of i th atom. and two atoms are space delimited

Limits:
0 < ai < 199
1 < n < 1000

Output Format
Print Determinant of the input matrix rounded up to 3 digits after decimal point, on console in the format shown in table below
 Line 1 For Valid Input E,where E is Integer stating maximum energy that can be produced For Invalid Input INVALID INPUT

Sample Inputs and Outputs
 Sr.no Input Output(Rounded upto Three Decimal digits) 1 `3 15 75 60` 8925 2 J INVALID INPUT 3 3 15 0 6 INVALID INPUT 4 3 5 5 199 INVALID INPUT 5 4 15 75 60 45 18515

(Note:-Please do not forget to end your program with a new line, else you may get a Compile Time Error from the Code Evaluation Engine
Note:-Participants submitting solutions in C language should not use functions from / as these files do not exist in gcc)

Brokerage

The current maximum intra-day brokerage offered is 0.03% for buying and 0.03% for selling.

Taxes

1. The service tax is of 10.36% only on brokerage.
2. The STT (Security Transaction Tax) is of 0.025% only selling amount.
3. The stamp duty on total turnover for a day which is 0.002%.
4. Finally you have to pay Regulatory charges on total turnover for a day which is 0.004%

Example:
Suppose the shares of Bank has been bought at Rs.315, quantity - 100 so the amount comes to Rs.315 x 100 = Rs.31500.
0.03% as brokerage on 31,500 which comes to Rs.9.45
Service Tax:
The service tax is 10.36% only on brokerage, so 10.36 % on Rs.9.45 comes to Rs 0.98.
Total charges you have pay on buying amount is:
The total brokerage + service tax which come to Rs.9.45 + Rs.0.98 = Rs.10.43

Suppose you sold Bank shares at Rs.316, Qty - 100 so the amount comes to Rs.31,600 (Rs.316 x 100 Qty shares)

Brokerage charge:

0.03% brokerage on 31600, comes to Rs.9.48 STT(Service Transaction Tax) only on selling amount
The STT (Service Transaction Tax) is 0.025% on selling amount (the selling amount is 31,600) which comes to Rs.7.9.
Total charges you have to pay on Selling amount = total brokerage + service tax + STT on selling amount is = Rs.9.48 + Rs.0.98 + Rs.7.9 = Rs.18.36
Total amount you have to pay on buying and selling is = Rs.10.43 (buying) + Rs.18.36 (selling) = Rs.28.79
Buying amount is 31500 and selling amount is 31600 which adds up to Rs. 61300
Stamp duty is 0.002% and Regulatory charges are 0.004% which adds up to 0.006%
So on total turnover amount (Rs. 61300) the stamp duty and regulatory charges comes to Rs 3.8.
So the total amount you have to pay including brokerage and all taxes is only Rs 28.79 + 3.8 = 32.58

Conclusion

So now the conclusion is you are paying Rs.31.02 while you earned the profit of Rs.100.
So your profit is Rs 100-32.58 = 67.42
User has to enter brokerage tax in %. and buying amount and selling amount and quantity of the share.
Now calculate the total profit or loss in this transaction.

Write a program to compute Profit or Loss statement for Transactions.

Input Format:

Input contains three integers N, L, X in each line

 Line1 Brokerage rate Line 2 Buying amount Line 3 Selling amount Line 4 Quantity

Assume STT to be fixed at 0.025%, Service Tax to be fixed at 10.36%, Stamp-duty on total turn-over is fixed at 0.002% and Regulatory charge on total turn-over is 0.004%

Output Format:

Print Profit or Loss as applicable with respect to transaction , and in next line print amount profit/loss faced

 Line 1 For Valid Input,printProfitOrLossFor Invalid Input,printInvalid Input Line 2 For Valid Input,printAmount of Profit / Loss faced in transaction

Sample Test Cases:

SNo.InputOutput
1
0.03
315
316
100
Profit
67.42
1
0.03
315
@
100
Invalid Input
1
0.03
315
315.32
100
Loss
0.53

Note:

Participants submitting solutions in C language should not use functions from / as these files do not exist in gcc
Note:

This question is inspired by an example of Brokerage calculations provided at
http://www.stockmarketindian.com/calculate_brokerage_charges.html

Helloworld

Bob is a newbie to programming and while learning the programming language he came to came the following rules:
1. Each program must start with '{' and will end with '}'.
2. Each program must contain only one main program. Main program will start with '<' and will end with '>'.
3. A program may or may not contain user defined fuctions but there is no limitation about the number of user definded functions present in the program. User defined program will start with '(' and will end with ')'.
4. Loops are allowed only inside the functions (this function can be either main function or user defined function(s)). Every loop will start wih '{' and will end with '}'
5. User defined function(s) are not allowed to define inside main function or user defined function(s).
6. Nested loops (loop inside a loop) are allowed.
7. Instructions can be defined any where inside the program.
8. If any of the above conditions does not met, then the program will generate compilation errors.
9. Today Bob has written his first program " Hello World ", but he is not sure about the correctness of the program now your task is to help him to find out whether his program will compile without any errors or not.

Input Format:

Each Input will contain a single line L, where L is a program written by Bob.

 Line 1 L,where L is a single line program written by Bob.

Constraints:

L is a text and can be composed of any of the characters {, }, (, ) , <, >and P, where P will represent the instruction.
L will contain single spaced characters where each character will represent the each line of the program.
Number of characters in the text < = 10000

Output Format:

 Line 1 For Valid Input,print“No Compilation Errors“, if there is no compilation errorFor Invalid Input,print“Compilation Error“

Sample Input and Output

SNo.InputOutput
1
{ < > ( P ) }
No Compilation Errors
2
{ < { } > ( { } ) )
Compilation Errors
3
{ ( { } ) }
Compilation Errors

Note:

Participants submitting solutions in C language should not use functions from / as these files do not exist in gcc

Hexogonal Triangle

In NASA, two researchers, Mathew and John, started their work on a new planet, but while practicing research they faced a mathematical difficulty. In order to save the time they divided their work.
So scientist Mathew worked on a piece and invented a number computed with the following formula:
A Mathew number is computed as follows using the formula:
H(n) = n(2n-1)
And scientist John invented another number which is built by the following formula which is called John number:
T(n) = n(n+1)/2
Now Mathew and John are jumbled while combining their work. Now help them combine their research work by finding out number in a given range that satisfies both properties. Using the above formula, the first few Mathew-John numbers are:
1 6 15 28... …

Input Format:

Input consists of 3 integers T1,T2,M separated by space . T1 and T2 are upper and lower limits of the range. The range is inclusive of both T1 and T2. Find Mth number in range [T1,T2] which is actually a Mathew-John number.
 Line 1 T1 T2 M,where T1 is upper limit of the range, T2 is lower limit of the range and M ,where Mth element of the series is required

Constraints:

0 < T1 < T2 < 1000000

Output Format:

Print Mth number from formed sequence between T1 and T2(inclusive).

 Line 1 For Valid Input,printPrint Mth number from formed sequence between T1 and T2OrNo number is present at this indexFor Invalid Input,printInvalid Input

Sample Input and Output

SNo.InputOutput
1
90 150 2
120
2
20 80 6
No number is present at this index
3
-5 3 a
Invalid Input

Note:

Participants submitting solutions in C language should not use functions from / as these files do not exist in gcc