0
내 코드입니다 : 나누기 기울기가 0
#include "stdafx.h"
#include <vector>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> point;
int numTorres, numEdificios;
vector<point> towervec;
vector<point> skyvec;
typedef vector<point>::const_iterator tower_iter;
typedef vector<point>::const_iterator sky_iter;
int noofpaths = 0;
int findslope(const point & i, const point & j, const point & k) {
int dx, dy, dx1, dy1;
dx = j.first - i.first;
dy = j.second - i.second;
int a = dy/dx;
dx1 = k.first - i.first;
dy1 = k.second - i.second;
int b = dy1/dx1;
if(a != b) {
int length1 = (j.first - i.first) * (j.first - i.first) + (j.second - i.second) * (j.second - i.second);
int length2 = (k.first - i.first) * (k.first - i.first) + (k.second - i.second) * (k.second - i.second);
if(length1 < length2) {
noofpaths++;
}
}
return noofpaths;
}
int main() {
int T;
int n, m;
cout << "enter the test cases" << endl;
cin >> T;
while(T--) {
cout << "towers and skyscrapers" << endl;
cin >> n >> m;
for(int i = 0; i < n; i++) {
point p;
cin >> p.first >> p.second;
towervec.push_back(p);
skyvec.push_back(p);
}
for(int i = 0; i < m; i++) {
point p;
cin >> p.first >> p.second;
skyvec.push_back(p);
}
for(tower_iter i = towervec.begin(); i != towervec.end(); i++) {
for(tower_iter j = i + 1; j != towervec.end(); j++) {
for(sky_iter k = skyvec.begin(); k != skyvec.end(); k++) {
int dx, dy;
noofpaths = findslope(*i, *j, *k);
cout << noofpaths;
}
}
}
}
return 0;
}
방법 제로 오류에 의해 분할을 극복하기. dx = 0 또는 dy = 0이거나 둘 다 0 인 경우 코드가 손상됩니다.
어떻게이 오류를 해결할 수 있습니까? 예를 들어 점 을 가져 가십시오. i = -1, -1j = 1, -1, k-1, -1. 나는 3 점이 동일 선상인지 찾기 위해 노력하고있다.
내가 말을해야 할 것, 이것은 "창조적 인 형식"사이에서 꽤 높은 거기 위 ... – Mysticial
그냥'0 수표'dy' 추가 ''dy''가 결코''0 '이 될 수 없도록 보장하십시오. –