Data Structure Assignment # 1
Solve a problem: Laser tower
A tower with N different height on a straight line was set up in order from left to right of a horizontal straight line, and a laser transmitter was installed at the top of each tower.
The laser transmitter of every tower emits a laser signal to the left of the horizontal straight line parallel to the surface of the earth, and a device for receiving the laser signal is installed on all the columns of the tower.
Laser signals emitted from one tower can only be received from one tower, which is first encountered.
The conditions of the problem are as follows.
1. The height of the i-th tower is hi, and all the towers stand in line and shoot
the beam to the left.
2. The other towers visible in the i-th tower are i-1, i-2, ...., 1.
3. For the first time, towers higher or equal than the current tower receive this
laser beam.
Given the number of towers N and the height of the towers, implement a program that identifies which tower receives the laser signals from each tower by using stack.
For example, suppose that five towers with heights of 6, 9, 5, 7, and 4 are in a row on a horizontal straight line, and that all towers emit laser signals to the left direction of a given tower sequence at the same time.
Then, the laser signal emitted from the fifth tower with a height of 4 is received by the fourth tower with the height of 7. 4
The signal from the fourth tower with the height of 7 is received by the second tower with the height of 9. 2
The signal from the third tower is also received by the second tower with a height of 9. 2
The signal from a second tower with a height of 9 and a first tower with a height of 6 will not be received by any tower. 0
So the output would be 0 0 2 2 4.
Input :
The first line gives the number of test cases T.
For each test case, the first line is given the natural number N (1 ≤ N ≤ 1,000), which is the number of towers.
In the second row, the heights of the N towers are given in order, separated by a space. The height of the towers is an integer from 1 to 1000.
Example :
Output :
In each test case, the index number of towers receiving the laser signals emitted from each tower in the order of the given towers is output with one space between them.
If there is no tower receiving the laser signal, it outputs 0.
Example :Assignment manual
Since the assignment will be graded by the automatic scoring tool, please submit only the c file through i-campus, when submitting the assignment. Please make the name of the c file “studentid_name”. (ex: 2019710068_John.c)
Please make sure to use “scanf” instead of “scanf_s”.
The assignment requires to implement functions that are related to stack such as “pop”,”push” and etc.
The assignment points will be given in proportion to the correct answer rate of the test cases.
Submission deadline is April 2.
Assignment points will be deducted by 10% per day.
To prevent the plagiarism of the project, we will perform a source code similarity check. If the assignment you have submitted is detected as a plagiarism, you will receive an F.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。