Skip to content

Instantly share code, notes, and snippets.

@RollingUpper
Created January 6, 2022 08:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RollingUpper/82cafe302b76a00f369c41c4b8ec5afd to your computer and use it in GitHub Desktop.
Save RollingUpper/82cafe302b76a00f369c41c4b8ec5afd to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int closest = 500;
int dist = 0;
/**
* Auto-generated code below aims at helping you parse
* the standard input according to the problem statement.
**/
int main()
{
int n; // the number of temperatures to analyse
cin >> n; cin.ignore();
for (int i = 0; i < n; i++) {
int t; // a temperature expressed as an integer ranging from -273 to 5526
cin >> t; cin.ignore();
int temp[i];
temp[i] = t;
dist = t;
if (temp[i] == 0) {
cout << temp[i];
}
else if (temp[i] < 0) {
for (int i = 0; dist < 0 ; i++) {
dist++;
}
}
if (temp[i] > 0) {
for (int i = 0; dist > 0; i++) {
dist--;
}
}
if (dist < closest){
closest = temp[i];
}
}
// Write an answer using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
cout << closest << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment