Вы находитесь на странице: 1из 9

CodeVita 2013 : Sequence (Longest Progressive Sequence)

Given a sequence, the objective is to find the longest progressive sequence arranged in
ascending order. Detailed descriptions are as:

Problem
A sequence is said to be progressive if it doesn’t decrease at any point in time.
For example 1 1 2 2 is a progressive sequence but 1 2 1 is not a progressive sequence. Let S
be the sequence and be represented by L spaced integers Ki, now your task is to find out the
first longest progressive sequence present in the given sequence (S).

Input Format:

First line will contain T, the length of the sequence and next line will contain T spaced
integers Ki (where i = 0,1, …,L).
Line 1 T,where T is the length of the sequence
Line 2 Ki,where Ki is integer in sequence separated by space

Constraints:

1<=T<=10^6(one million)
1<=Ki<=10^9(one billion)

Output Format:

Line 1 longest progressive sequence present in the given sequence

Sample Test Cases:

SNo. Input Output

1 4 112
1121

2 5 122
12122

I have not followed coding standards while solving the problems.

/**
*
* @author VIK VIKASH VIKKU
* Business Logic class
*/
import java.util.ArrayList;
import java.util.Scanner;

public class LongestProgressiveSequence {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
ArrayList<Integer> ls = new ArrayList<Integer>();
Integer[] temp = new Integer[0];
for (int i = 0; i < t; i++) {
int num = sc.nextInt();
if (!(ls.isEmpty())) {
if (num >=ls.get(ls.size()-1 )) {

ls.add(num);
} else {

if(ls.size()>temp.length)
temp=ls.toArray(temp);
ls.clear();
ls.add(num);
}

} else {
ls.add(num);
}
}

if(ls.size()>temp.length)
{
temp=ls.toArray(temp);
ls.clear();
}
for (int i = 0; i < temp.length; i++) {
if(i<temp.length-1)
System.out.print(temp[i]+" ");
else
System.out.println(temp[i]);

}
}

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 8925
3 15 75 60

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.
Your buying amount Rs.31500 (Rs.315x100 Qty shares) Brokerage charge
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
Your selling amount:
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
Your total turn over is calculated by adding the buying amount and selling amount.
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
For Valid Input,print
Profit
Or
Line 1
Loss

For Invalid Input,print


Invalid Input

Line 2 For Valid Input,print


Amount of Profit / Loss faced in transaction

Sample Test Cases:

SNo. Input Output

0.03
Profit
1 315
67.42
316
100

0.03
1 315 Invalid Input
@
100

0.03
Loss
1 315
0.53
315.32
100

Note:

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

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.
6. User defined function(s) are not allowed to define inside main function or
user defined function(s).
7. Nested loops (loop inside a loop) are allowed.
8. Instructions can be defined any where inside the program.
9. If any of the above conditions does not met, then the program will generate
compilation errors.
10. 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.

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


Line 1

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:

For Valid Input,print


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

“Compilation Error“

Sample Input and Output

SNo. Input Output


1 No Compilation Errors
{<>(P)}
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.
T1 T2 M,where T1 is upper limit of the range, T2 is lower limit of the range and M
Line 1 ,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).


For Valid Input,print

Print Mth number from formed sequence between T1 and T2


Or
Line 1
No number is present at this index

For Invalid Input,print

Invalid Input

Sample Input and Output

SNo. Input Output


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

Note:

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

Вам также может понравиться