Hi,
Please find the program and code below.
If your requirement is in another programming language ., this code can be migrate to c and c++ easily.
package staticclasses;
import java.util.Scanner;
public class Tumble {
public static void main(String[] args) {
int size;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of steps");
size = sc.nextInt();
int tumble[]=new int[size];
System.out.println("Enter height of the steps");
for(int i=0;i<size;i++){
tumble[i] = sc.nextInt();
}
sc.close();
int minPoint=0,lastElement=0; //min point shows the tumble value at left side
int maxPoint=-1; //max point shows the tumble value at right side tubme 9 6 1, min =9 max=1
int tumbHeight=0; //it will store tumble height
minPoint = tumble[0]; //initialize min point from 0 position
for(int i=1;i<size;i++){
lastElement=tumble[i-1]; //keep track of last element to see if new element is in increasing order or decreasing order
if(tumble[i]<lastElement){ //if new element is in increasing order
maxPoint = tumble[i]; //assign that to max point
}else{ //else
if(maxPoint!=-1){ //if maxpoint is not -1.
if(tumbHeight <( minPoint - maxPoint) ){ //calculate new tumble height.
tumbHeight = minPoint - maxPoint; //if new height is greater than old one set it
}
}
minPoint = tumble[i]; //min point is corrent element
maxPoint =-1; //max point is -1
}
}
if(maxPoint!=-1){ //this step is to check height for last element
if(tumbHeight <( minPoint - maxPoint) ){
tumbHeight = minPoint - maxPoint;
}
}
System.out.println("Tumble has height "+tumbHeight);
}
}
Given an array of integers representing heights of consecutive steps, we say that a tumble is...
write the solution of the program by python 3 language : I need the program using list : You are given a non-decreasing sequence of n positive integers a1,a2,…,an. Print the number of distinct values in the sequence. For example, if the sequence is 1,2,2,2,3,4,4,5,7,10, the answer is 6 since distinct values are 1,2,3,4,5,7,10. Input The first line contains a positive integer n (1≤n≤1000) — the length of the sequence. The second line contains n space-separated positive integers a1,a2,…,an (1≤ai≤1000)...
Plz i want answer these question using list in python programme. You are given two sequences of n integers: 21, 22, ...,an and b1,b2, ..., bn Print a sequence of 2n integers created by alternating elements from the given sequences: a1, 61, 42, 62, a3, 63, ..., an, bn. Input The first line contains a positive integer n (1 <n<1000) - the length of the sequences The second line contains n space-separated integers 01, 02, ..., an (-1000 <a; <...
Given an array A[] of integers find sum of product of all pairs of array elements Input: First line consists of T test cases. First line of every test case consists of N, denoting number of elements of array. Second line consists of elements of array. Output: Single line output, print the sum of products. Constraints: 1<=T<=100 1<=N<=100 Solve the problem using pointers and (if possible) using operators Example: Input: 2 3 1 3 4 4 2 3 4 5...
C++ Given a sequence of integers, check to see if the sequence constitutes a heap Input: the first line is an integer n(0 < n < 10000), The second line is n integers Output: If the sequence is a very small heap, that is, the top of the heap is the smallest element, then output "min heap". If the sequence is a very large heap, the top of the heap is the largest element The output includes one line with...
I want this using while loop This using stringin python Use list or some thing in python Using list in python I want answer as soon as posdible E. Last Number time limit per test: 1 second memory limit per test: 256 megabytes input standard input output standard output You are given a sequence of positive integers aj, , 03, ... Print the last element of the sequence. Input The input consists of multiple lines. The i-th line contains a...
C Programming Language Problem Title : Climbing Stairs Bibi climbs stairs of a multi-leveled building. Every time Bibi climbs a set of stairs, she counts the steps starting from 1 to the number of steps in that particular set of stairs while climbing the stairs. For example if she climbs two set of stairs, the first containing 5 steps and the second containing 3 steps, she will say 1, 2, 3, 4, 5, 1, 2, 3 and the total number...
C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...
Preferably in python but java is good too Task 1: Minimum Spanning Trees For this warm-up task you are to implement any efficient minimum spanning tree algorithm that takes a sequence of edge-weighted graphs and outputs the minimum cost weight of a spanning tree of each Input Format For this assignment we use adjacency matrices with positive integer weights. Here a zero entry at row i and column J indicates that no edge i] exists in the graph. The first...
write the solution of the program by python 3 language : I need the program using list : You are given a sequence of n positive integers a1,a2,…,an, where n is even. Swap adjacent elements in the given sequence and print the resulting sequence: a2,a1,a4,a3,a6,a5,… Input The first line contains a positive even integer n (2≤n≤1000) — the length of the sequence. The second line contains n space-separated integers a1,a2,…,an (1≤ai≤1000) — the elements of the sequence. Output Print n...
write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other in the sequence. Input The first line contains an integer n...