Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <vector>
- #include <queue>
- #include "band.h"
- #include "bandSummit.h"
- bool cmpByX(Band p1, Band p2);
- bool cmpByY(Band p1, Band p2);
- int main()
- {
- //the example given band list as vector
- /* - - - example input - - - - - - */
- Band b1(9,7,9), b2(9,5,7), b3(22,14,2), b4(32,8,5), b5(34,6,7);
- std::vector<Band> bandList;
- bandList.push_back(b4);
- bandList.push_back(b2);
- bandList.push_back(b5);
- bandList.push_back(b1);
- bandList.push_back(b3);
- bandList.push_back(Band(51, 3, -3));
- bandList.push_back(Band(55, 3, -5));
- /* - - - example input END - - - */
- //sort by nearest X position
- std::sort(bandList.begin(), bandList.end(), cmpByX);
- //sort by heigh
- std::sort(bandList.begin(), bandList.end(), cmpByY);
- std::vector<Band> acceptedBands;
- //for every exisiting band
- for (int i = 0; i < bandList.size(); i++)
- {
- //initialize band list if empty
- if (acceptedBands.size() == 0)
- {
- acceptedBands.push_back(bandList[i]);
- continue;
- }
- for (int j = 0; j < acceptedBands.size(); j++)
- {
- if (bandList[i].getX1() < acceptedBands[j].getX1() || bandList[i].getX1() > acceptedBands[j].getX2())//check if X1 is placed outside
- {
- if (bandList[i].getX2() < acceptedBands[j].getX1() || bandList[i].getX2() > acceptedBands[j].getX2())//check if X2 is placed outside
- {
- //nothin
- }
- else
- {
- bandList[i].setX2(acceptedBands[j].getX1()); // 'cut' the line
- }
- //break only if that was last band to compare
- if (j == acceptedBands.size() - 1)
- {
- acceptedBands.push_back(bandList[i]);
- break;
- }
- }
- else
- {
- if (bandList[i].getX2() > acceptedBands[j].getX2())
- {
- bandList[i].setX1(acceptedBands[j].getX2());//modify
- //break only if that was last band to compare
- if (j == acceptedBands.size() - 1)
- {
- acceptedBands.push_back(bandList[i]);
- break;
- }
- }
- else
- {//cant be added
- break;
- }
- }
- }
- }
- for (int j = 0; j < acceptedBands.size(); j++)
- {
- printf("X:%i, Y:%i \n", acceptedBands[j].getX1(), acceptedBands[j].getY());
- printf("X:%i, Y:%i \n", acceptedBands[j].getX2(), acceptedBands[j].getY());
- }
- _getch();
- return 0;
- }
- bool cmpByX(Band b1, Band b2)
- {
- return b1.getX1() < b2.getX1();
- }
- bool cmpByY(Band b1, Band b2)
- {
- return b1.getY() > b2.getY();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement