Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me answer these simple coding questions. You can write the code in either Python3 or Java8 ; whichever one is easier and faster.

Please help me answer these simple coding questions. You can write the code in either Python3 or Java8 ; whichever one is easier and faster. Please also provide screenshots of your output after entering the inputs; it should match the sample inputs and outputs in the question. Thank You!

PROB #1:

-----------------------------------------------------------------------------------------------------------------------------image text in transcribed

PROB. #2:

-----------------------------------------------------------------------------------------------------------------------------

image text in transcribed

Goran has five wooden pieces arranged in a sequence. There is a number between 1 and 5 inscribed on every piece, so that every number appears on exactly one of the five pieces. Goran wants to order the pieces to form the sequence 1,2,3,4,5 and does it like this 1. If the number on the first piece is greater than the number on the second piece, swap them 2. If the number on the second piece is greater than the number on the third piece, swap them 3. If the number on the third piece is greater than the number on the fourth piece, swap them 4. If the number on the fourth piece is greater than the number on the fifth piece, swap them 5. If the pieces don't form the sequence 1,2,3, 4,5, go to step 1 Write a program that, given the initial ordering of the pieces, outputs the ordering after each swap Input The first line contains five integers separated by single spaces, the ordering of the pieces. The numbers will be between 1 and 5 (inclusive) and there will be no duplicates. The initial ordering will not be 1,2,3, 4,5. Output After any two pieces are swapped, output the ordering of the pieces, on a single line separated by spaces Sample Input 1 Sample Output 1 2 1 5 3 4 1 2 5 3 4 1 2 3 5 4 1 2 3 4 5 Sample Input 2 Sample Output 2 2 3 4 15 2 3 14 5 2 134 5 1 2 3 4 5 2 3 4 5 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

=+What is the nature of the unions in the particular country?

Answered: 1 week ago