forked from uva-cs/pdr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
traveling-skeleton.cpp.html
63 lines (54 loc) · 7.63 KB
/
traveling-skeleton.cpp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite">
<title>traveling-skeleton.cpp</title>
</head>
<body style="background-color:white">
<pre><b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><iostream></span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><cstdlib></span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000"><algorithm></span>
<b><span style="color:#0000FF">using</span></b> <b><span style="color:#0000FF">namespace</span></b> std<span style="color:#990000">;</span>
<b><span style="color:#000080">#include</span></b> <span style="color:#FF0000">"middleearth.h"</span>
<span style="color:#009900">float</span> <b><span style="color:#000000">computeDistance</span></b><span style="color:#990000">(</span><span style="color:#008080">MiddleEarth</span> me<span style="color:#990000">,</span> <b><span style="color:#0000FF">const</span></b> string<span style="color:#990000">&</span> start<span style="color:#990000">,</span> <span style="color:#008080">vector<string></span> dests<span style="color:#990000">);</span>
<span style="color:#009900">void</span> <b><span style="color:#000000">printRoute</span></b><span style="color:#990000">(</span><b><span style="color:#0000FF">const</span></b> string<span style="color:#990000">&</span> start<span style="color:#990000">,</span> <b><span style="color:#0000FF">const</span></b> vector<span style="color:#990000"><</span>string<span style="color:#990000">>&</span> dests<span style="color:#990000">);</span>
<span style="color:#009900">int</span> <b><span style="color:#000000">main</span></b><span style="color:#990000">(</span><span style="color:#009900">int</span> argc<span style="color:#990000">,</span> <span style="color:#009900">char</span><span style="color:#990000">**</span> argv<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<i><span style="color:#9A1900">// check the number of parameters</span></i>
<b><span style="color:#0000FF">if</span></b> <span style="color:#990000">(</span>argc <span style="color:#990000">!=</span> <span style="color:#993399">6</span><span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
cout <span style="color:#990000"><<</span> <span style="color:#FF0000">"Usage: "</span> <span style="color:#990000"><<</span> argv<span style="color:#990000">[</span><span style="color:#993399">0</span><span style="color:#990000">]</span> <span style="color:#990000"><<</span> <span style="color:#FF0000">" <world_height> <world_width> "</span>
<span style="color:#990000"><<</span> <span style="color:#FF0000">"<num_cities> <random_seed> <cities_to_visit>"</span> <span style="color:#990000"><<</span> endl<span style="color:#990000">;</span>
<b><span style="color:#000000">exit</span></b><span style="color:#990000">(</span><span style="color:#993399">0</span><span style="color:#990000">);</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">// we'll assume the parameters are all well-formed</span></i>
<span style="color:#009900">int</span> width <span style="color:#990000">=</span> <b><span style="color:#000000">stoi</span></b><span style="color:#990000">(</span>argv<span style="color:#990000">[</span><span style="color:#993399">1</span><span style="color:#990000">]);</span>
<span style="color:#009900">int</span> height <span style="color:#990000">=</span> <b><span style="color:#000000">stoi</span></b><span style="color:#990000">(</span>argv<span style="color:#990000">[</span><span style="color:#993399">2</span><span style="color:#990000">]);</span>
<span style="color:#009900">int</span> num_cities <span style="color:#990000">=</span> <b><span style="color:#000000">stoi</span></b><span style="color:#990000">(</span>argv<span style="color:#990000">[</span><span style="color:#993399">3</span><span style="color:#990000">]);</span>
<span style="color:#009900">int</span> rand_seed <span style="color:#990000">=</span> <b><span style="color:#000000">stoi</span></b><span style="color:#990000">(</span>argv<span style="color:#990000">[</span><span style="color:#993399">4</span><span style="color:#990000">]);</span>
<span style="color:#009900">int</span> cities_to_visit <span style="color:#990000">=</span> <b><span style="color:#000000">stoi</span></b><span style="color:#990000">(</span>argv<span style="color:#990000">[</span><span style="color:#993399">5</span><span style="color:#990000">]);</span>
<i><span style="color:#9A1900">// create the world, and select your itinerary</span></i>
<span style="color:#008080">MiddleEarth</span> <b><span style="color:#000000">me</span></b><span style="color:#990000">(</span>width<span style="color:#990000">,</span> height<span style="color:#990000">,</span> num_cities<span style="color:#990000">,</span> rand_seed<span style="color:#990000">);</span>
<span style="color:#008080">vector<string></span> dests <span style="color:#990000">=</span> me<span style="color:#990000">.</span><b><span style="color:#000000">getItinerary</span></b><span style="color:#990000">(</span>cities_to_visit<span style="color:#990000">);</span>
<i><span style="color:#9A1900">// TODO: YOUR CODE HERE</span></i>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">// This method will compute the full distance of the cycle that starts</span></i>
<i><span style="color:#9A1900">// at the 'start' parameter, goes to each of the cities in the dests</span></i>
<i><span style="color:#9A1900">// vector IN ORDER, and ends back at the 'start' parameter.</span></i>
<span style="color:#009900">float</span> <b><span style="color:#000000">computeDistance</span></b><span style="color:#990000">(</span><span style="color:#008080">MiddleEarth</span> me<span style="color:#990000">,</span> <b><span style="color:#0000FF">const</span></b> string<span style="color:#990000">&</span> start<span style="color:#990000">,</span> <span style="color:#008080">vector<string></span> dests<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<i><span style="color:#9A1900">// TODO: YOUR CODE HERE</span></i>
<b><span style="color:#0000FF">return</span></b> <span style="color:#993399">0</span><span style="color:#990000">;</span>
<span style="color:#FF0000">}</span>
<i><span style="color:#9A1900">// This method will print the entire route, starting and ending at the</span></i>
<i><span style="color:#9A1900">// 'start' parameter.</span></i>
<i><span style="color:#9A1900">// The output should be similar to:</span></i>
<i><span style="color:#9A1900">// Erebor -> Khazad-dum -> Michel Delving -> Bree -> Cirith Ungol -> Erebor</span></i>
<span style="color:#009900">void</span> <b><span style="color:#000000">printRoute</span></b><span style="color:#990000">(</span><b><span style="color:#0000FF">const</span></b> string<span style="color:#990000">&</span> start<span style="color:#990000">,</span> <b><span style="color:#0000FF">const</span></b> vector<span style="color:#990000"><</span>string<span style="color:#990000">>&</span> dests<span style="color:#990000">)</span> <span style="color:#FF0000">{</span>
<i><span style="color:#9A1900">// TODO: YOUR CODE HERE</span></i>
<span style="color:#FF0000">}</span>
</pre>
</body>
</html>