Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <sstream>
- 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);
- // std::string input;
- // std::getline(std::cin, input);
- std::stringstream stream(temps);
- int pmin = 1000;
- int nmax = -1000;
- int result;
- while(1){
- int n;
- stream >> n;
- if(!stream)
- break;
- std::cout << "Found integer: " << n << "\n";
- //find smallest positive number
- if(n>=0 && n < pmin)
- {
- pmin = n;
- cout << "pmin="<< pmin << endl;
- }
- else if(n<0 && n > nmax) // find biggest negative integer
- {
- nmax = n;
- cout << "nmax="<< nmax << endl;
- }
- } //end of while loop
- //check which is closer to 0 from pmin and nmax
- if (abs(pmin) < abs(nmax))
- {
- result = pmin;
- }
- else if(abs(pmin)>abs(nmax))
- {
- result = nmax;
- }
- else
- {
- result = pmin;
- }
- cout << result << endl;
- //cout << temps << endl;
- //cout << "result" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement