Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<fstream>
- using namespace std;
- struct point {
- double x;
- double y;
- };
- struct matrix {
- double tgs [10][10];
- };
- void getdata(int value) {
- bool isntCorrect = false;
- do {
- cout << "Enter number of points: ";
- cin >> value;
- if ((value > 2147483647) || (value < -2147483647)) {
- cout << "Invalid file data. Value from " << 2147483647 << "to " << -2147483647 << " expected";
- isntCorrect = true;
- }
- } while (isntCorrect);
- }
- void getInput(point points [10], int size) {
- bool isntCorrect = false;
- for (int i = 0; i < size; i++) {
- do {
- cout << "Enter Point(x, y) #" << (i + 1) << ": ";
- cin >> points[i].x;
- cin >> points[i].y;
- if ((points[i].x < -200000) || (points[i].x > 200000) || (points[i].y < -20000) || (points[i].y > 200000)) {
- isntCorrect = true;
- cout << "Invalid point. Please enter this data again";
- }
- } while(isntCorrect);
- }
- }
- int compareDouble(double a, double b) {
- double e = 0.001;
- if ((a == INFINITY) && (b == INFINITY)) {
- return 0;
- }
- }
- double getTg(point p1, point p2) {
- if (compareDouble(p2.x, p1.x) == 0 ) {
- return INFINITY;
- } else {
- return (p2.y - p1.y) / (p2.x - p1.x);
- }
- }
- matrix getTgs(point points [10], int size) {
- matrix tgs;
- tgs.tgs[0][0] = 0;
- for (int i = 0; i < size; i++) {
- for (int j = i + 1; j < size; j++) {
- tgs.tgs[i][j] = getTg(points[i],points[j]);
- }
- }
- return tgs;
- }
- int getPath(int map [10][10], matrix tgs, int lineindex, double tg, int step) {
- int counter = 1;
- int size = sizeof(map);
- for (int i = lineindex + 1; i < size; i++) {
- if (map [lineindex] [i] == step) {}
- else {
- if (compareDouble(tgs.tgs[lineindex][i],tg) == 0) {
- map [lineindex] [i] = step;
- counter = 1 + getPath(map,tgs,lineindex,tg,step);
- }
- }
- }
- return counter;
- }
- int getLongestPath(matrix tgs,int size) {
- int step = 0;
- int maxpath = 0;
- int path;
- int map [10][10];
- for (int i = 0; i < size; i++) {
- for (int j = i + 1; j < size; j++) {
- step++;
- path = getPath(map,tgs,i,tgs.tgs[i][j],step);
- if (path > maxpath) {
- maxpath = path;
- }
- }
- }
- return maxpath;
- }
- void body() {
- cout << "This program counts points on same line";
- int n = 0;
- matrix tgs;
- point points [10];
- getdata(n);
- getInput(points,n);
- tgs = getTgs (points [10], n);
- cout << "Number of points: " << getLongestPath(tgs,n);
- }
- int main() {
- body();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement