Graphing calculators are devices capable of plotting graphs, given a user-defined function. Given a function , the view window (domain and range), and an -increment (described later), replicate the functionality of a graphing calculator by plotting the graph in the output.
For every coordinate in the domain and range, graph layout will consist as follows:
- Empty space will be represented by a period (
.
) - The origin (0, 0) will be represented as a
+
- X and Y axis lines will be represented by
-
and|
, respectively - The actual points where the graph exists will be represented by a
#
For example, the function would look like:
.....|...#.
.....|..#..
.....|.#...
.....|#....
.....#.....
....#|.....
...#.|.....
--#--+-----
.#...|.....
#....|.....
To get full points, your program must also allow for -increment specification. An -increment defines the difference between every value of in , essentially signifying the precision of the output of the graphing program. For example, with an -increment of , your program should only find the value of for every integer , such as , , , and so on. Plotting with an -increment of 1 would produce such result:
..........|..........
.......#..|..#.......
..........|..........
..........|..........
..........|..........
..........|..........
........#.|.#........
..........|..........
..........|..........
.........#|#.........
----------#----------
..........|..........
..........|..........
where only the rounded result of for every integer is displayed.
However, with an -increment of , really begins to take shape:
.......#..|..#.......
.......#..|..#.......
.......#..|..#.......
.......#..|..#.......
.......##.|.##.......
........#.|.#........
........#.|.#........
........#.|.#........
........##|##........
.........#|#.........
---------###---------
..........|..........
..........|..........
Note that you must round your output.
Input Specification
The first line will contain a string representing . The string is guaranteed to only have the following possibly space-separated characters: x
, +
, -
, *
, /
, ^
, (
, )
, .
, and the digits from 0-9. Note that multiplication will be represented with the *
, so 2x
(instead of 2 * x
) will not be valid input. However, placing a negative sign before a number is valid and should be accounted for (e.g. -x
).
The next line of input will contain the integers , , , , and the number . The first four (, , , ) represent the domain and range of the graph, or the left, right, bottom, and top values of the viewing window, where and , and . specifies the -interval of . For 75% of the points, .
Keep in mind that you must obey proper operation order. For 25% of the points, the input will not contain any brackets.
Output Specification
Graph using the appropriate view port.
Sample Input 1
x - 5
-10 10 -10 10 1
Sample Output 1
..........|..........
..........|..........
..........|..........
..........|..........
..........|..........
..........|.........#
..........|........#.
..........|.......#..
..........|......#...
..........|.....#....
----------+----#-----
..........|...#......
..........|..#.......
..........|.#........
..........|#.........
..........#..........
.........#|..........
........#.|..........
.......#..|..........
......#...|..........
.....#....|..........
Sample Input 2
(x - 5) * (x + 1)
-20 20 -15 15 1
Sample Output 2
....................|....................
....................|....................
....................|....................
....................|....................
....................|....................
....................|....................
....................|....................
....................|....................
..................#.|.....#..............
....................|....................
....................|....................
....................|....................
....................|....................
....................|....................
....................|....................
-------------------#+----#---------------
....................|....................
....................|....................
....................|....................
....................|....................
....................#...#................
....................|....................
....................|....................
....................|#.#.................
....................|.#..................
....................|....................
....................|....................
....................|....................
....................|....................
....................|....................
....................|....................
Sample Input 3
(x-5)*(x-3)/(x-5)
-10 10 -10 10 0.01
Sample Output 3
..........|..........
..........|..........
..........|..........
..........|.........#
..........|........#.
..........|.......#..
..........|......#...
..........|.....#....
..........|....#.....
..........|...#......
----------+--#-------
..........|.#........
..........|#.........
..........#..........
.........#|..........
........#.|..........
.......#..|..........
......#...|..........
.....#....|..........
....#.....|..........
...#......|..........
Sample Input 4
x^3/100
-10 10 -10 10 0.01
Sample Output 4
..........|.........#
..........|........##
..........|........#.
..........|........#.
..........|.......##.
..........|.......#..
..........|......##..
..........|.....##...
..........|....##....
..........|...##.....
------#########------
.....##...|..........
....##....|..........
...##.....|..........
..##......|..........
..#.......|..........
.##.......|..........
.#........|..........
.#........|..........
##........|..........
#.........|..........
Comments