Skip to content

Instantly share code, notes, and snippets.

@nagy3n
Created August 10, 2015 01:23
Show Gist options
  • Save nagy3n/f8bab655bb2fd085c372 to your computer and use it in GitHub Desktop.
Save nagy3n/f8bab655bb2fd085c372 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
/**
* 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();
string TEMPS; // the N temperatures expressed as integers ranging from -273 to 5526
getline(cin, TEMPS);
string delimiter,token;
delimiter=" ";
int i,min=9999999;
if(N==0)
{
cout<<"0"<<endl;
return 1;
}
size_t pos = 0;
if(N==1)
{
min=stoi(TEMPS);
cout << min << endl;
return 2;
}
while ((pos = TEMPS.find(delimiter)) != string::npos) {
token = TEMPS.substr(0, pos);
i=stoi(token);
cerr << i << endl;
if(abs(i)<abs(min))
{
min=i;
}
else if(i==abs(min))
{
min=abs(min);
}
TEMPS.erase(0, pos + delimiter.length());
}
cout << min << endl;
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment