SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.     int amountofcases;
  9.     cin >> amountofcases;
  10.  
  11.     int i = 0;
  12.     while (i < amountofcases) {
  13.         int amountofFloors;
  14.         int sizeofFloor;
  15.         cin >> amountofFloors;
  16.         int sizeofFloors[amountofFloors];
  17.         string coloursofFloors[amountofFloors];
  18.         i++;
  19.         for (int i = 0; i < amountofFloors; i++) {
  20.             cin >> sizeofFloor;
  21.             if (sizeofFloor > 0) {
  22.                 sizeofFloors[i] = sizeofFloor;
  23.                 coloursofFloors[i] = "blue";
  24.             } else {
  25.                 sizeofFloors[i] = sizeofFloor*(-1);
  26.                 coloursofFloors[i] = "red";
  27.             }
  28.         }
  29.  
  30.         for (int i = 0; i < amountofFloors; i++) {
  31.             int floorSize = sizeofFloors[i];
  32.             string colourSize = coloursofFloors[i];
  33.             int previousfloorSize = i - 1;
  34.             while (previousfloorSize >= 0 && sizeofFloors[previousfloorSize] < floorSize) {
  35.                 sizeofFloors[previousfloorSize + 1] = sizeofFloors[previousfloorSize];
  36.                 coloursofFloors[previousfloorSize + 1] = coloursofFloors[previousfloorSize];
  37.                 previousfloorSize--;
  38.             }
  39.             sizeofFloors[previousfloorSize + 1] = floorSize;
  40.             coloursofFloors[previousfloorSize + 1] = colourSize;
  41.         }
  42.         int maxsize = 0;
  43.         int temp = -1;
  44.  
  45.         for (int i = 0; i < amountofFloors-1; i++){
  46.  
  47.             if (coloursofFloors[i] != coloursofFloors[i+1]) {
  48.                 if ((i == 0) || (maxsize == 0)) {
  49.                     maxsize++;
  50.                     maxsize++;
  51.                 } else {
  52.                     maxsize++;
  53.                     }
  54.  
  55.             } else {
  56.                 if (maxsize == 0) {
  57.  
  58.                 } else if (maxsize > 0) {
  59.                     if (maxsize > temp) {
  60.                         temp = maxsize;
  61.                     }
  62.                     maxsize = 0;
  63.                 }
  64.             }
  65.         }
  66.         if (maxsize > temp) {
  67.             cout << maxsize << endl;
  68.         } else {
  69.             cout << temp << endl;
  70.         }
  71.  
  72.  
  73.     }
  74.  
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top