Knowee
Questions
Features
Study Tools

Array-4Banana Saplings are planted in a garden. Different varieties of saplings are planted.N saplings are planted in M rows.Read the N and M values.Read the cost of each sapling.Sort the cost of the sapling rowwise in ascending order and print the cost of saplings as two-dimensional array.Sample Input3 4 (Row and Column value)12 10 13 14 10 8 7 12 9 8 10 12 Sample Output10 12 13 14 7 8 10 12 8 9 10 12

Question

Array-4Banana Saplings are planted in a garden. Different varieties of saplings are planted.N saplings are planted in M rows.Read the N and M values.Read the cost of each sapling.Sort the cost of the sapling rowwise in ascending order and print the cost of saplings as two-dimensional array.Sample Input3 4 (Row and Column value)12 10 13 14 10 8 7 12 9 8 10 12 Sample Output10 12 13 14 7 8 10 12 8 9 10 12

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a step-by-step guide on how to solve this problem:

  1. Read the values of N and M. These represent the number of saplings and the number of rows respectively. In the sample input, N=3 and M=4.

  2. Create a two-dimensional array with N rows and M columns. This array will hold the cost of each sapling.

  3. Read the cost of each sapling. In the sample input, the costs are given as a series of numbers. Fill the two-dimensional array with these costs. Each row in the array represents a row of saplings in the garden.

  4. Sort each row of the array in ascending order. This can be done using a sorting algorithm such as bubble sort, insertion sort, or quick sort. The sorted array represents the cost of the saplings in each row, sorted from lowest to highest.

  5. Print the sorted two-dimensional array. Each row should be printed on a new line, with the costs separated by a space. In the sample output, the costs are printed as follows:

10 12 13 14 7 8 10 12 8 9 10 12

This output shows the cost of the saplings in each row, sorted in ascending order.

This problem has been solved

Similar Questions

Banana Saplings are planted in a garden. Different varieties of saplings are planted.N saplings are planted in M rows.Read the N and M values.Read the cost of each sapling.Sort the cost of the sapling rowwise in ascending order and print the cost of saplings as two-dimensional array.Sample Input3 4 (Row and Column value)12 10 13 14 10 8 7 12 9 8 10 12 Sample Output10 12 13 14 7 8 10 12 8 9 10 12 Input

anana Saplings are planted in a garden.Different varieties of saplings are planted.N saplings are planted in M rows.Read the N and M values .Read the cost of each saplings.Print the cost of saplings as two dimensional array.Sample Input3 4 (Row and Column value)12 10 13 14 10 8 7 12 9 8 10 12 Sample Output12 10 13 14 10 8 7 12 9 8 10 12

On the occasion of Van Mahotsav it was decided by the Secretary of Residents Welfare Association to plant saplings of Ashoka trees and Mango trees in the locality. Accordingly Ashoka trees were planted in (3x + 1) rows having (x3 + x2 – 1) trees in each row and Mango trees were planted in (x – 3) rows having (2x2 + 1) trees in each row.(i) Find the total number of trees planted.

Geek and Geekina, the top students in their class, were vying for the leadership role. To determine the leader, their teacher assigned them arrays, arr1[] to Geek and arr2[] to Geekina of size n. The task was simple: calculate the cost of each array. The cost of the array is defined as the summing of VAL(a[i]) for each i in [0,n-1].VAL(x)=minimum number of operations to convert x to 0 or 1.In each operation, you can take any prime factor of the remaining value and subtract it from x.For example,  if we have 6, and if we subtract 3 from it, then our remaining value will become 3 and then we can not subtract 2 from it because 2 is not the prime factor of the current value of 3.Due to their busy schedules, Geek and Geekina have sought assistance in calculating the cost of their arrays. So your task is to return  1 if the cost of arr1 is less than or equal to the cost of arr2.  otherwise, it should return 0. Example 1:Input:n=3arr1={1,1,2}arr2={1,1,1}Output:0Explanation:VAL(1) is 0 and VAL(2) is 1 (2->0).Now Cost of arr1 is 1 and Cost of arr2 is 0.So 0 is the answer Cost(arr1)>Cost(arr2).

Geek and Geekina, the top students in their class, were vying for the leadership role. To determine the leader, their teacher assigned them arrays, arr1[] to Geek and arr2[] to Geekina of size n. The task was simple: calculate the cost of each array. The cost of the array is defined as the summing of VAL(a[i]) for each i in [0,n-1].VAL(x)=minimum number of operations to convert x to 0 or 1.In each operation, you can take any prime factor of the remaining value and subtract it from x.For example,  if we have 6, and if we subtract 3 from it, then our remaining value will become 3 and then we can not subtract 2 from it because 2 is not the prime factor of the current value of 3.Due to their busy schedules, Geek and Geekina have sought assistance in calculating the cost of their arrays. So your task is to return  1 if the cost of arr1 is less than or equal to the cost of arr2.  otherwise, it should return 0. Example 1:Input:n=3arr1={1,1,2}arr2={1,1,1}Output:0Explanation:VAL(1) is 0 and VAL(2) is 1 (2->0).Now Cost of arr1 is 1 and Cost of arr2 is 0.So 0 is the answer Cost(arr1)>Cost(arr2).  Example 2:Input:n=5arr1={3,5,6,9,10}arr2={2,5,8,7,9}Output:1Explanation:VAL(x) of 2,3,5,6,7,8,9,10 are 1(2→0),1(3→0),1(5→0),2(6→3→0),1(7→0),3(8→6→3→0),3(9→6→3→0),2(10→5→0)respectively.Now  Cost of arr1 is 9 and Cost of arr2 is 9. So 1 is the answer as Cost(arr1)<=Cost(arr2). Your Task:You don't need to read input or print anything. Your task is to complete the function costComparison() which takes an integer n, integer array arr1[], and integer array arr2[] as input parameters respectively and you have to return 1 if the cost of arr1 is less than or equal to the cost of arr2.  otherwise, it should return 0.Constraints:1<=n<=1051<=arr1[i],arr1[i]<=105arr1.length==arr2.length

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.