193030

2012 02. B Правоъгълници препокриване

Mar 31st, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1. // primeren input:
  2. // 3 // 3 testa
  3. // 1 20 // panica 1 = 20
  4. // 2 30 //
  5. // 3 50 //
  6. // OUTPUT: 100
  7. //
  8.  
  9.  
  10. #include <iostream>
  11. #include <string>
  12. #include <string.h>
  13. #include <cstdlib>
  14. #include <sstream>      // std::stringstream
  15.  
  16. using namespace std;
  17.  
  18.  
  19. string input = "123";
  20. string output;
  21. int broiTestove = 1;
  22. int broiPravoygylnici =4;
  23. int cordinates[3][3] = {};
  24. bool overLapping = 0;
  25. int counter = 0;
  26. int maxCounter = 0;
  27. int main()
  28. {
  29.     cin >> broiTestove;
  30.  
  31.     cin >> broiPravoygylnici;
  32.  
  33.     for(int i =0; i<=4; i++)
  34.     {
  35.  
  36.         getline(cin, input);
  37.         stringstream  stream(input);
  38.  
  39.         stream >> input;
  40.         cordinates[i][0] = atoi(input.c_str());
  41.  
  42.         stream >> input;
  43.         cordinates[i][1] = atoi(input.c_str());
  44.  
  45.         stream >> input;
  46.         cordinates[i][2] = atoi(input.c_str());
  47.  
  48.         stream >> input;
  49.         cordinates[i][3] = atoi(input.c_str());
  50.     }
  51.  
  52.         for(int i =0; i<4; i++) {
  53.  
  54.  
  55.  
  56.  
  57.             if (cordinates[i][0] > cordinates[i+1][0] || cordinates[i+1][0] > cordinates[i][0])
  58.                 overLapping = 0;
  59.  
  60.  
  61.             // If one rectangle is above other
  62.             if (cordinates[i][1] < cordinates[i+1][1] || cordinates[i+1][1] < cordinates[i][1])
  63.            // if (l1.y < r2.y || l2.y < r1.y)
  64.                 overLapping = 0;
  65.  
  66.             else
  67.                 overLapping = 1;
  68.  
  69.  
  70.         int a1 = abs(cordinates[i][0]-cordinates[i][2]);
  71.         int b1 = abs(cordinates[i][1]-cordinates[i][3]);
  72.         int area1 = a1*b1;
  73.  
  74.         int a2 = abs(cordinates[i+1][0]-cordinates[i+1][2]);
  75.         int b2 = abs(cordinates[i+1][1]-cordinates[i+1][3]);
  76.         int area2 = a1*b1;
  77.         if((area1 > area2) && overLapping == 1)
  78.         {
  79.             counter++;
  80.             if(counter >maxCounter)
  81.                 maxCounter = counter;
  82.  
  83.         }
  84.         else
  85.         {
  86.             counter =0;
  87.         }
  88.  
  89.  
  90.  
  91. }
  92.  
  93.  
  94.         cout << maxCounter;
  95. }
Add Comment
Please, Sign In to add comment