update solution of lab02
This commit is contained in:
@@ -2,13 +2,13 @@
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include "line.h"
|
||||
|
||||
|
||||
#include "point.h"
|
||||
|
||||
// A helper function to parse a collection of files from an input file.
|
||||
std::vector<Line>& load(std::ifstream &istr) {
|
||||
std::vector<Line> load(std::ifstream &istr) {
|
||||
std::vector<Line> roads;
|
||||
float x1,y1,z1,x2,y2,z2;
|
||||
while (istr >> x1 >> y1 >> z1 >> x2 >> y2 >> z2) {
|
||||
@@ -28,13 +28,14 @@ void organize(std::vector<Line> &roads) {
|
||||
void print(const std::vector<Line> &roads) {
|
||||
|
||||
// print each road in the current, sorted order (steepest first)
|
||||
for (int i = 0; i < roads.size(); i++) {
|
||||
//for (int i = 0; i < roads.size(); i++) {
|
||||
for (size_t i = 0; i < roads.size(); i++) {
|
||||
std::cout << roads[i] << std::endl;
|
||||
}
|
||||
|
||||
// count the number of roads with gradient less than 10%
|
||||
int count;
|
||||
for (unsigned int i = roads.size() - 1;
|
||||
for (int i = roads.size() - 1;
|
||||
i >= 0 && gradient(roads[i]) < 10.0;
|
||||
i--) {
|
||||
count++;
|
||||
|
||||
Reference in New Issue
Block a user