| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11422 | Shape |
|
| 11423 | Simulating Iterators |
|
Description
Warning: You are not allowed to use malloc and free
Following the lecture slide :
Giving a bass-class Shape and 3 derived class : Triangle, Rectangle, Circle
You need to calculate the area and the perimeter of each shape.
note : You need to do some basic check: if the given information cannot form a shape (e.g. height of the rectangle is negative number....etc), then the area and perimeter would be both 0)
Input
There are only 3 shapes in this problem :
- Triangle, following by its 3 edges. (e.g. Triangle 3 4 5)
- Rectangle, following by its width and height. (e.g. Rectangle 5 7)
- Circle, following by its radius and the value of pi. (e.g. Circle 2 3.14)
Output
Ouput the total area and perimeter of all the shapes.
Sample Input Download
Sample Output Download
Partial Judge Code
11422.cppPartial Judge Header
11422.hTags
Discuss
Description
Warning: You are not allowed to use:
1. any static variables
2. any variables which is not inside a function
3. malloc and free
You are required to implement a iterator.
Random_iter is a array-like pointer which goes next or previous element by increasing or decreasing one memory address.
Bidirect_iter is a linked list-like pointer which goes next or previous element by the next or prev data member of Node.
(After you learning template, you will know how iterator exactly work.)
Input
The first line contains a non-negative integer N (0<N<100) that specifies the number of elements.
The second line contains 2*N integer that specifies the next position of elements and the value ([-32767,32768)) of the next element.
For example, 4 24713 2 21367 5 -3338 1 1893 3 -4723 0 -16458 means
node 0: value is -16458, next is node 4
node 1: value is 1893, next is node 2
node 2: value is 21367, next is node 5
node 3: value is -4723, next is node 1
...
The thrid line contains a non-negative integer H (H<N) that specifies which element is head.
The following lines contain an instruction I (0<=I<4). The meaning of I is shown below:
0 means distance. Containg a non-negative P (P<N, from input) that specifies the distance from head. You have to display the distance between current position and P.
1 means set value. Replace the value of current position with input integer.
2 means next. Set the current position to next.
3 means prev. Set the current position to previous.
Current position is initialized with 0, which points to head.
Output
Complete Node (constructor), Iter (constructor), Random_iter (distance_, next_, prev_ and constructor) and Bidirect_iter (distance_, next_, prev_ and constructor).