Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- struct dot {
- int x, y;
- };
- istream& operator>>(istream& is, dot& a) {
- is >> a.x >> a.y;
- return is;
- }
- struct line {
- int a, b, c;
- line(const dot& A, const dot& B) {
- a = B.y - A.y;
- b = A.x - B.x;
- c = A.y * (B.x - A.x) - A.x * (B.y - A.y);
- }
- };
- bool on_line(dot& a, line& l) {
- return a.x * l.a + a.y * l.b + l.c == 0;
- }
- int sign(int s) {
- if (s < 0) {
- return -1;
- } else if (s > 0) {
- return 1;
- } else {
- return 0;
- }
- }
- int main() {
- dot a, b, c, d;
- cin >> a >> b >> c >> d;
- line l1(a, b);
- line l2(c, d);
- if (l1.a * l2.b != l1.b * l2.a) {
- cout << 1 << " ";
- double x = - ((l1.c * l2.b - l2.c * l1.b) * 1.0 / (l1.a * l2.b - l2.a * l1.b));
- double y = - ((l1.a * l2.c - l2.a * l1.c) * 1.0 /(l1.a * l2.b - l2.a * l1.b));
- cout << fixed << setprecision(2) << x << " " << y << "\n";
- return 0;
- } else if (l1.c == l2.c) {
- cout << 2 << "\n";
- return 0;
- } else {
- cout << 0 << "\n";
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement