1.

n the center of the city, there is a large rectangular ground. The Corporation has decided to construct a Cricket stadium for school and college students. However, the area is currently being used as an unauthorized parking zone. To prevent further misuse, the Corporation plans to enclose the stadium with a fence.

To assist the workers, they intend to place a thick rope around the ground and purchase only the exact length required. Additionally, they plan to cover the entire ground with a carpet during the rainy season, ensuring that only the necessary quantity is bought. They seek your help in determining the exact length of the rope and the total area of the carpet needed.

Input Format:
The input consists of two integers:

  • The first integer represents the length of the ground.
  • The second integer represents the breadth of the ground.

Output Format:
The output consists of two integers:

  • The first integer represents the total length of the rope required.
  • The second integer represents the total area of the carpet needed.
  • Case 1

    Input (stdin)

    50
    20
    Output (stdout)

    140
    1000

    Case-2

    Input (stdin)

    70
    40
    Output (stdout)

    220
    2800

2.

Mrs. Bhulbhul is extremely frugal and always looks for ways to save money, even on small purchases. One day, she heard about a discount offer at a mall and decided to buy multiple items to maximize her savings. However, the discount applies only when at least two items are purchased, and since each item has a different discount rate, she finds it challenging to calculate the exact amount she saves.

To simplify the billing process, she seeks your help in developing an automated discount calculator.

Input Format:
The input consists of:

  • Two floating-point values representing the prices of the first and second items.
  • A third floating-point value representing the discount percentage.

Output Format:
The output consists of three floating-point values:

  • The total price before applying the discount.
  • The final price after applying the discount.
  • The amount saved due to the discount.
  • Case 1

    Input (stdin)

    20.50
    45.40
    10
    Output (stdout)

    65.90
    59.31
    6.59

    Case-2

    Input (stdin)

    65.90
    59.31
    6.59

    Output (stdout)

    125.21
    116.96
    8.25

3.

Blackbeard, one of history’s most infamous and feared pirates, commanded a fleet of four ships and led a pirate army of 300 men. At the peak of his career, he even defeated the renowned warship, HMS Scarborough, in a fierce sea battle. Known for his ruthless tactics, he captured over forty merchant ships in the Caribbean and showed no hesitation in eliminating prisoners.

One day, Blackbeard and his three trusted pirates discovered a hidden treasure filled with gold coins. Soon after, another pirate, Long Ben, joined them. They all agreed to divide the treasure fairly. Blackbeard decided to give x% of the total treasure to Long Ben first. From the remaining coins, he claimed y% for himself. The remaining treasure was then divided equally among his three pirates.

Your task is to write a program that calculates the share of gold coins for each of them.


Input Format:

The input consists of three integers:

  1. The total number of gold coins.
  2. The percentage of gold coins allocated to Long Ben (x%).
  3. The percentage of the remaining gold coins taken by Blackbeard (y%).

Output Format:

The output consists of three integers:

  1. Long Ben’s share of the gold coins.
  2. Blackbeard’s share of the gold coins.
  3. The share of each of the three remaining pirates (equal share).

Case 1

Input (stdin)

729
65
87
Output (stdout)

473
222
11

Case-2

Input (stdin)

72
6
8
Output (stdout)

4
5
21

 

4.

Booka, an alien, struggles to understand how time is measured on Earth. Concepts like days, weeks, months, and years are completely new to him. Your task is to help Booka by explaining how days convert into years, months, and weeks using a program.


Input Format:

The input consists of a single integer representing the total number of days.

Output Format:

The output consists of three integers:

  1. The number of years.
  2. The number of weeks.
  3. The remaining days.

Case 1

Input (stdin)

373


Output (stdout)

1
1
1

Case-2

Input (stdin)

365
Output (stdout)

1
0
0

 

5.

After bypassing the three-headed dog, Harry, Ron, and Hermione found themselves in a mysterious room while searching for the Sorcerer’s Stone. The door behind them shut instantly, leaving them with only one way forward—a massive door with a four-digit number engraved on it.

Harry and Ron tried various spells, but the door wouldn’t budge. Frustrated, they turned to Hermione for help. She noticed an inscription above the door that read:

  • “I will always be four.”
  • “I can only be opened when you add my first and last and enter it.”
  • “If you find a sign, you should not consider it.”

Can you help Hermione decode the number and open the door?


Input Format:

The input consists of a single four-digit integer written on the door.

Output Format:

The output is a single integer, which is the sum of the first and last digit.

 

Case 1

Input (stdin)

1001


Output (stdout)

2

 

Case-2

Input (stdin)

2381
Output (stdout)

3

1. Write a  program to determine the largest of three given numbers.

Input Format:
The input consists of three integers.

Sample Input & Output:

Input:

7
9
5

Output:

9 is the greatest.

Input:

diff
-1
-33
-45

Output:

-1 is the greatest.
 
 

2.

Quadrants

Write a program to find the quadrant in which the given x and y coordinates are present in a graph. If it is in 1st Quadrant, then display Ist Quadrant, If it is in 2nd Quadrant, then display IInd Quadrant, If it is in 3rd Quadrant, then display IIIrd Quadrant, If it is in 4th Quadrant, then display IVth Quadrant and If it is in center display Origin. INPUT FORMAT: Input consists of 2 integers. First input corresponds to x coordinate. Second input corresponds to y coordinate.

SAMPLE INPUT: 

5

6

SAMPLE OUTPUT: 

Ist Quadrant

Input (stdin)

-5
6
Output (stdout)

IInd Quadrant

3.

Dora is very much interested in gardening and she decides to plant more trees in her garden. She plants trees in the order of rows and columns. She numbered the trees in column wise order. She planted the mango trees only in the second column from both first and last. But later when the trees grew up, she forgot where she planted mango trees. So help her find out whether the given tree number is a number of mango trees or not. Display whether “It is a mango tree” or “It is not a mango tree”. INPUT FORMAT: Input consists of 3 integers. First input corresponds to the number of rows. Second input corresponds to the number of columns. Third input corresponds to the tree number.

SAMPLE INPUT:

5

5

20

SAMPLE OUTPUT:

It is a mango tree

4.

The electricity board charges based on the units consumed: up to 200 units at ₹0.50 per unit, 201-400 units at ₹0.65 per unit with an additional ₹100 charge, 401-600 units at ₹0.80 per unit with an additional ₹200 charge, and above 600 units at ₹1.25 per unit with an additional ₹425 charge. The input is a single integer representing the units consumed, and the output is the total electricity bill prefixed with “Rs.”.

SAMPLE INPUT:

200

SAMPLE OUTPUT:

Rs.100

Input (stdin)

250
Output (stdout)

Rs.263

5.

Nanu, who recently bought a car, sets off for a temple without checking the petrol level. After traveling a certain distance, he realizes his mistake and checks the petrol level to determine if he can reach his destination. Given the mileage (kilometers per liter), the available petrol (liters), and the remaining distance to travel (kilometers), determine if he can reach the destination. If the total distance that can be covered with the available petrol is greater than or equal to the required distance, print “Can reach”; otherwise, print “Cannot reach”.

Input & Output Format:

Input: A float representing the mileage, followed by two integers representing the available petrol and the remaining distance to be traveled.
Output: A string, either “Can reach” or “Cannot reach”.

SAMPLE INPUT:

11

6

67

SAMPLE OUTPUT:

Cannot reach

Input (stdin)

9
30
250
Output (stdout)

Can reach

 

1.print the following series 2, 4, 7, 12, 21…..

Case 1

Input (stdin)

5

Output (stdout)

2 4 7 12 21

Case-2

Input (stdin)

4

Output (stdout)

2 4 7 12


2.print the following series 1, 4, 27, 256….
Case 1

Input (stdin)

5

Output (stdout)

Enter n value
1 4 27 256 3125

Case-2

Input (stdin)

6

Output (stdout)

Enter n value
1 4 27 256 3125 46656

3.print the following series 10, 5, 60, 15, 110….
Case 1

Input (stdin)

5
Output (stdout)

Enter n value
10 5 60 15 110

Case-2

Input (stdin)

10

Output (stdout)

Enter n value
10 5 60 15 110 25 160 35 210 45

4.print the following series 101, 103, 107, 109….
Case 1

Input (stdin)

8

Output (stdout)

101 103 107 109 113 127 131 137

Case-2

Input (stdin)

19

Output (stdout)

101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193

5.print the following series 0, 2, 6, 12, 20…..
Case 1

Input (stdin)

5

Output (stdout)

Enter n value
0 2 6 12 20

 

 

Case-2

Input (stdin)

1

Output (stdout)

Enter n value
0

All Pattern Programs

1. Write a program to insert an element in an array at the given position. If the position where the element is to be inserted is greater than the size of the array display “Invalid Input”.

INPUT FORMAT:

Input consists of 3 integers and 1 array.

The first integer corresponds to the size of the array.

The second integer corresponds to the position where the element is to be inserted.

The third integer corresponds to the element to be inserted.

Case 1:

Case 2:

 

SAMPLE INPUT:

5

1

2

3

4

5

4

10

SAMPLE OUTPUT:

Array after insertion is:

1

2

3

10

4

5

2. Delete an element

Write a program to delete an element from the given location in an array..

SAMPLE INPUT:

5

1

2

3

4

5

4

SAMPLE OUTPUT:

Array after deletion is:

1

2

3

5

3. Write a program to search for the presence of an element in an array.

INPUT FORMAT:

Case 2:

Input (stdin)

5
5
10
15
12
25
20


Output (stdout)

20 is not present in the array

 

Input consists of 2 integers and 1 array.

The first integer corresponds to the size of the array.

the next two integers corresponds to the element to be Array

The last integer corresponds to the element to be searched.

Case 1:

SAMPLE INPUT:

2

10

15

10

SAMPLE OUTPUT:

10 is present in the array

4. Write a program to count the number of distinct elements in an array. INPUT FORMAT: Input consists of 1 integer and 1 array. The first integer corresponds to the size of the array.

SAMPLE INPUT:

6

2

6

6

4

5

5

SAMPLE OUTPUT:

There are 4 distinct elements in the array.

5. Write a program to remove the duplicate elements from an array.
INPUT FORMAT:

Input consists of 4 integers.

The first integer corresponds to the size of the array.

The next three integers correspond to the elements in the array.

OUTPUT FORMAT:

The output consists of an array with no duplicate elements.

SAMPLE INPUT:

3

1

5

1

SAMPLE OUTPUT:

1

5

  • Reverse a Number – Write a function reverseNumber(int num) to reverse a given integer. For example, input 12345 should return 54321, and input 1000 should return 1.

  • Count Digits in a Number – Implement countDigits(int num), which returns the number of digits in a given integer. For instance, input 1234 should return 4, and 1001001 should return 7.

  • Find the Greatest Common Divisor (GCD) – Define findGCD(int a, int b) to compute the GCD of two numbers. For example, input (20, 30) should return 10, and (35, 10) should return 5.

  • Check if a Number is Armstrong – Create isArmstrong(int num), which determines if a number is an Armstrong number (sum of its own digits raised to the power of the number of digits equals the number). For example, input 153 should return true, while 123 should return false.

  • Count Vowels in a String – Write countVowels(String str) to count the number of vowels in a string. For instance, input "hello" should return 2, and "rhythm" should return 0.

  • 1.Magic Square

    A magic square is an arrangement of numbers (usually integers) in a square grid,

    where the numbers in each row, and in each column, and the numbers in the forward and backward main diagonals,

    all add up to the same number. Write a program to find whether a given matrix is a magic square or not.

    Input Format:

    The input consists of (n*n+1) integers.

    The first integer corresponds to the number of rows/columns in the matrix.

    The remaining integers correspond to the elements in the matrix.

    The elements are read in rowwise order, first row first, then second row and so on.

    Assume that the maximum value of m and n is 5.

     

    Output Format:

    Print “yes” if it is a magic square. Print “no” if it is not a magic square.

     

    Sample Input 1:

    2

    4 5

    5 4

     

    Sample Output 1:

    no

    ·

    Input (stdin)

    2
    4 5
    5 4


    Output (stdout)

    no

    2.Diagonal Matrix. A square matrix which has zeros everywhere other than the main diagonal.

    Entries on the main diagonal may be any number, including 0.

    Write a program to find whether a given matrix is a diagonal matrix or not.

    Input Format:

    The input consists of (n*n+1) integers.

    The first integer corresponds to the number of rows/columns in the matrix.

    The remaining integers correspond to the elements in the matrix.

    The elements are read in rowwise order, first row first,

    then second row and so on. Assume that the maximum value of m and n is 5.

     

    Output Format:

    Print yes if it is a diagonal matrix. Print no if it is not a diagonal matrix.

     

    Sample Input :

    2

    4 5

    5 4

     

    Sample Output:

    no

    Input (stdin)

    2
    4 5
    5 4


    Output (stdout)

    no

    3.Upper Triangular Matrix

    An upper triangular matrix is a square matrix in which all the elements below the diagonal are zero.

    That is, all the non-zero elements are in the upper triangle:

    Write a JAVA program to find whether a given matrix is an upper triangular matrix or not.


    Input Format:

    The input consists of (n*n+1) integers.

    The first integer corresponds to the number of rows/columns in the matrix.

    The remaining integers correspond to the elements in the matrix. The elements are read in rowwise order,

    first row first, then second row and so on. Assume that the maximum value of m and n is 5.

     

    Output Format:

    Print “yes” if it is an upper triangular matrix . Print “no” if it is not an upper triangular matrix.

     

    Sample Input 1:

    2

    1 2

    0 3

     

    Sample Output 1:

    yes

    Input (stdin)

    2
    1 2
    0 3


    Output (stdout)

    yes

    4.A lower triangular matrix is a square matrix in which all the elements above the diagonal are zero.

    That is, all the non-zero elements are in the lower triangle:

    Write a JAVA program to find whether a given matrix is a lower triangular matrix or not.


    Input Format:

    The input consists of (n*n+1) integers. The first integer corresponds to the number of rows/columns in the matrix.

    The remaining integers correspond to the elements in the matrix. The elements are read in row wise order,

    first row first, then second row and so on. Assume that the maximum value of m and n is 5.

     

    Output Format:

    Print “yes” if it is a lower triangular matrix . Print “no” if it is not a lower triangular matrix.

     

    Sample Input 1:

    2

    1 0

    2 3

     

    Sample Output 1:

    yes

    Input (stdin)

    2
    1 0
    2 3


    Output (stdout)

    yes

    a

    1. Total no of Char_String

    Write a Program to count the total number of characters in a string.


    Sample Input :

    I love programming@

    Sample Output :

    Total number of characters in a string: 17

    Input (stdin)

    Happy learning !!!


    Output (stdout)

    Total number of characters in a string: 16

    2. The Anagram String_Java

    Write a Program to determine whether two strings are the anagram


    Sample Input :

    Apple

    apple

     

    Sample Output :

    Anagram

    Input (stdin)

    Apple
    app


    Output (stdout)

    Not an anagram

    3. Divide a String_Java

    Write a Program to divide a string in ‘N’ equal parts. Here, our task is to divide the string S into n equal parts. We will print an error message if the string cannot be divisible into n equal parts otherwise all the parts need to be printed as the output of the program. To check whether the string can be divided into N equal parts, we need to divide the length of the string by n and assign the result to variable chars. If the char comes out to be a floating-point value, we can’t divide the string otherwise run for loop to traverse the string and divide the string at every chars interval.


    Input Format :

    Input consist of a Strings and Integer

    Output Format :

    Output consist of an Integer and String

     

    Sample Input :

    Happy learning

    3

    Sample Output:

    Sorry this string cannot be divided into 3 equal parts.

    Input (stdin)

    Happy learning
    2

     

    Output (stdout)

    2 equal parts of given string are
    Happy l
    earning

    4.Subset of a String_Java

    Program to find all subsets of a string and print it in sorted order. In this program, all the subsets of the string need to be printed. The subset of a string is the character or the group of characters that are present inside the string. All the possible subsets for a string will be n(n+1)/2. For example, all possible subsets of a string “FUN” will be F, U, N, FU, UN, FUN.


    Input Format :

    Input consist of a String

    Otput Format :

    Output consist of a String

     

    Sample Input :

    java

    Output Format :

    a

    a

    av

    ava

    j

    ja

    jav

    java

    v

    va

    Input (stdin)

    AbcD


    Output (stdout)

    Sorted Substring
    a
    ab
    abc
    abcd
    b
    bc
    bcd
    c
    cd
    d

    1.Problem Statement:

      N boys are sitting in a circle. Each of them have some apples in their hand. You find that the total number of the apples can be divided by N. So you want to divide the apples equally among all the boys. But they are so lazy that each one of them only wants to give one apple to one of the neighbors at one step. Calculate the minimal number of steps to make each boy have the same number of apples.

    Input:

    The first line of input is an integer N. 2 <= N <= 10000 The second line is N integers indicates the number of apples of the ith boy. Each integer is positive and no more than 109. 

    Output:

    A single line contains the minimal number of steps to make each boy have the same number of apples.

     

    Sample input

    4

    1 3 9 7

    Sample output

    8

     

    Explanation: Here are the 8 steps starting from (1,3,9,7):

    (2,3,9,6)

    (3,3,9,5)

    (3,4,8,5)

    (3,5,7,5)

    (3,6,6,5)

    (3,7,5,5)

    (4,6,5,5)

    (5,5,5,5)

     

     

    2. Decode a string

    Input: i2a4c3

    Output: iiaaaaccc