include
include
include
include
include
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
string my_int_str; // temporary hold integer string
int input;
int abs_;
int result = 5527;
cin >> n; cin.ignore();
string temps; // the n temperatures expressed as integers ranging from -273 to 5526
getline(cin, temps);
cerr << n << endl;
cerr << temps << endl;
cerr << temps[1] << endl;
// Only works if this is executed first?????? Weird
// If I comment this out program won't execute other for loop?????
// It's a mystery
for(int i =0; i<1; i++){
cerr << "int i is " << i << endl;
}
for( int y, i = 0; (y+i) < temps.length(); y++ ) {
int t;
for( ; (temps[y+i] != ' ') &&( (y+i) < temps.length()); i++ ) {
my_int_str = my_int_str + temps[y+i];
}
input = stoi(my_int_str);
if( (abs(input)) < abs(result)) {
result = input;
} else if( ((abs(input)) == abs(result)) && (input > 0)) {
result = input;
}
cerr << "input integer " << input << endl;
my_int_str.clear();
}
// find shortest distance to 0. If a distance repeats then positive temp wins.
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
// cout << "result" << endl;
cout << result << endl;
}
Program won't work unless I insert that first "do nothing" for loop??? Must be haunted....