SA has the largest army that exists in the world. In USA it is always officer's main worry to order his soldiers on parade correctly. ering soldiers is not really such a problem. If a platoon consists of n nem have different rank (from 1 - lowest to n - highest) and on should be lined up from left to right in increasing order of rank. le, doesn't it? Well, Sgt Johnny thought the same, until one day he th a new command. He soon discovered that his elite commandos do the fighting, and leave the thinking to their superiors. So, when ollcall the soldiers lined up in fairly random order it was not because of discipline, but simply because they couldn't work out how to form ect order of ranks, Sgt Johnny was not at all amused, particularly as

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Using python solve the given problems:
Problem: USA has the largest army that exists in the world. In USA it is always
the military officer's main worry to order his soldiers on parade correctly.
Luckily, ordering soldiers is not really such a problem. If a platoon consists of n
men, all of them have different rank (from 1 - lowest to n - highest) and on
parade they should be lined up from left to right in increasing order of rank.
Sounds simple, doesn't it? Well, Sgt Johnny thought the same, until one day he
was faced with a new command. He soon discovered that his elite commandos
preferred to do the fighting, and leave the thinking to their superiors. So, when
at the first rollcall the soldiers lined up in fairly random order it was not because
of their lack of discipline, but simply because they couldn't work out how to form
a line in correct order of ranks. Sgt Johnny was not at all amused, particularly as
he soon found that none of the soldiers even remembered his own rank. Over the
years of service every soldier had only learned which of the other soldiers were
his superiors. But Sgt Johnny was not a man to give up easily when faced with a
true military challenge. After a moment's thought a solution of brilliant
simplicity struck him and he issued the following order: "men, starting from the
left, one by one, do: (step forward; go left until there is no superior to the left of
you; get back in line).". This did indeed get the men sorted in a few minutes. The
problem was solved. for the time being.
The next day, the soldiers came in exactly the same order as the day before, and
had to be rearranged using the same method. History repeated. After some
weeks, Sgt Johnny managed to force each of his soldiers to remember how many
men he passed when going left, and thus make the sorting process even faster.
Input:
1
010
Output:
213
Transcribed Image Text:Using python solve the given problems: Problem: USA has the largest army that exists in the world. In USA it is always the military officer's main worry to order his soldiers on parade correctly. Luckily, ordering soldiers is not really such a problem. If a platoon consists of n men, all of them have different rank (from 1 - lowest to n - highest) and on parade they should be lined up from left to right in increasing order of rank. Sounds simple, doesn't it? Well, Sgt Johnny thought the same, until one day he was faced with a new command. He soon discovered that his elite commandos preferred to do the fighting, and leave the thinking to their superiors. So, when at the first rollcall the soldiers lined up in fairly random order it was not because of their lack of discipline, but simply because they couldn't work out how to form a line in correct order of ranks. Sgt Johnny was not at all amused, particularly as he soon found that none of the soldiers even remembered his own rank. Over the years of service every soldier had only learned which of the other soldiers were his superiors. But Sgt Johnny was not a man to give up easily when faced with a true military challenge. After a moment's thought a solution of brilliant simplicity struck him and he issued the following order: "men, starting from the left, one by one, do: (step forward; go left until there is no superior to the left of you; get back in line).". This did indeed get the men sorted in a few minutes. The problem was solved. for the time being. The next day, the soldiers came in exactly the same order as the day before, and had to be rearranged using the same method. History repeated. After some weeks, Sgt Johnny managed to force each of his soldiers to remember how many men he passed when going left, and thus make the sorting process even faster. Input: 1 010 Output: 213
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY