Advertisement
xTheEc0

CodinGame.com // Temperatures // Easy

Oct 22nd, 2015
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. /**
  9.  * Auto-generated code below aims at helping you parse
  10.  * the standard input according to the problem statement.
  11.  **/
  12. int main()
  13. {
  14.     int n; // the number of temperatures to analyse
  15.     cin >> n; cin.ignore();
  16.     int temps[n];
  17.     int mark;
  18.    
  19.     for (int i = 0; i < n; i++) cin >> temps[i];
  20.    
  21.     sort(temps, temps+n);
  22.    
  23.     for (int i = 0; i < n; i++)
  24.     {
  25.         if (temps[i] > 0)
  26.         {
  27.             mark = i;
  28.             break;
  29.         }
  30.        
  31.     }
  32.    
  33.     if (mark == 0) mark = n-1;
  34.    
  35.     if (n == 0) cout << n << endl;
  36.     else if (temps[0] == 0 || temps[0] == 1) cout << temps[0] << endl;
  37.     else if (n == 1) cout << temps[0] << endl;
  38.     else if (-1 * temps[mark-1] < temps[mark]) cout << temps[mark-1] << endl;
  39.     else cout << temps[mark] << endl;
  40.    
  41.    
  42.    // cout << "result" << endl;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement