Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Copyright (c) 2013 by xerpi */
- #include <iostream>
- using namespace std;
- struct Rectangle {
- int x_esq, x_dre, y_baix, y_dalt;
- };
- void llegeix(Rectangle& r);
- int relacio(const Rectangle& r1, const Rectangle& r2);
- int main() {
- int n;
- cin >> n;
- for (int i = 0; i < n; ++i) {
- Rectangle r1, r2;
- llegeix(r1);
- llegeix(r2);
- int resultat = relacio(r1, r2);
- if (resultat == 0)
- cout << "els rectangles no intersecten" << endl;
- else if(resultat == 1)
- cout << "el primer rectangle es interior al segon" << endl;
- else if (resultat == 2)
- cout << "el segon rectangle es interior al primer" << endl;
- else if (resultat == 3)
- cout << "els rectangles intersecten" << endl;
- else
- cout << "els rectangles son iguals" << endl;
- }
- }
- int relacio(const Rectangle& r1, const Rectangle& r2)
- {
- if (r1.x_esq == r2.x_esq and r1.x_dre == r2.x_dre and
- r1.y_baix == r2.y_baix and r1.y_dalt == r2.y_dalt) {
- return 4;
- }
- if ((r1.x_esq >= r2.x_esq) and (r1.x_dre <= r2.x_dre) and
- (r1.y_baix >= r2.y_baix) and (r1.y_dalt <= r2.y_dalt)) {
- return 1;
- } else if ((r2.x_esq >= r1.x_esq) and (r2.x_dre <= r1.x_dre) and
- (r2.y_baix >= r1.y_baix) and (r2.y_dalt <= r1.y_dalt)) {
- return 2;
- } else {
- if ((r1.x_dre < r2.x_esq) or (r1.y_baix > r2.y_dalt) or
- (r1.x_esq > r2.x_dre) or (r1.y_dalt < r2.y_baix)) {
- return 0;
- } else {
- return 3;
- }
- }
- }
- void llegeix(Rectangle& r)
- {
- cin >> r.x_esq >> r.x_dre >> r.y_baix >> r.y_dalt;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement