Lab Mid-Term Exam (100)
Answer all of the following questions. Each of them contains 10 Marks
1 WAP that will take n integers into an array. Now find out the number of occurrences for each of the unique numbers. Each line of the output will be a unique number that exists in the array and its frequency. You can print them in any order.
Sample input | Sample output |
---|---|
8 | |
2 8 1 3 2 6 4 3 | 1 => 1 |
2 => 2 | |
3 => 2 | |
4 => 1 | |
6 => 1 | |
8 => 1 | |
4 | |
2 2 10 2 | 2 => 3 |
10 => 1 |
2 WAP that will take n integers into an array A and m positive integers into array B. Now find the difference (set operation) of array A and B or (A-B).
Sample input | Sample output |
---|---|
8 | |
7 8 1 5 2 6 4 3 | |
6 | |
1 3 6 0 9 2 | 7 8 5 4 |
3 | |
1 2 3 | |
2 | |
4 5 | 1 2 3 |
3 Farina is a hard worker. But she also loves shopping a lot. Each day she earns some money and spends some on shopping. Fortunately, she has a credit card without any restrictions (it can have any amount of negative/positive balance). Initially, her credit card has a balance of 0. But she becomes UPSET when her credit card balance goes negative otherwise, she remains HAPPY.
Input:
The first line contains a number of Test Case T. Each of the test cases contains the following lines:
Output:
For each Test case there will be a new line where For each query Print 0 if Farina is UPSET otherwise print 1.
Sample | Input | Output | Explanation |
---|---|---|---|
1 | 2 | ||
5 | |||
10 5 2 3 1 | |||
8 15 1 2 10 | |||
3 | |||
0 | |||
1 | |||
3 | |||
3 | |||
7 10 1 | |||
3 2 7 | |||
1 | |||
2 | 1 0 0 | ||
1 | Number of days: 5 | ||
Farina's earning: 10 5 2 3 1 | |||
Farina's expense: 8 15 1 2 10 | |||
Number of queries: 3 | |||
After 0th day Farina's balance is (10 – 8) = 2 which is positive, so she is HAPPY. | |||
After 1st day Farina's balance is (10+5 - 8 - 15) = -8 which is negative, so she is UPSET. | |||
2 | 1 | ||
4 | |||
10 1 1 2 | |||
7 4 4 4 | |||
2 | |||
1 | |||
3 | 1 0 | After 1st day Farina's balance is (10+1 - 7 - 4) = 0 which is not negative, so she is HAPPY. |
4 WAP that will take (m x n) positive integer inputs into a matrix of dimension m x n. Now replace all the duplicate integers by -1 in that matrix. Finally display it.
Sample input | Sample output |
---|---|
3 3 | |
1 7 3 | |
7 4 5 | |
3 5 6 | 1 7 3 |
-1 4 5 | |
-1 -1 6 | |
2 6 | |
2 2 2 2 2 2 | |
6 5 4 3 2 1 | |
2 -1 -1 -1 -1 -1 | |
6 5 4 3 -1 1 | |
5 WAP that will take (n x n) integer inputs into a square matrix of dimension n (where n must be an odd number). Then calculate the sum of the integers based on the following position pattern (consider only the boxed position during the sum). Please see the input-output.