Advertisement
cska1312

06. Squares

May 11th, 2023
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <utility>
  4. #include <vector>
  5. #include <sstream>
  6. #include <cmath>
  7. using namespace std;
  8.  
  9. vector<int> square_numbers;
  10.  
  11. void push_suqare_number(int n)
  12. {
  13.  vector<int>::iterator i = square_numbers.begin();
  14.  
  15. while(i != square_numbers.end() && *i > n)
  16. i++;
  17.  
  18. square_numbers.insert(i, n);
  19. }
  20.  
  21. int main()
  22. {
  23. string str;
  24. getline(cin, str);
  25. istringstream istr(str);
  26.  
  27. int num;
  28. while( istr >> num )
  29. {
  30. int sqrtN = sqrt(num);
  31. if( (sqrtN*sqrtN) == num)
  32.  push_suqare_number(num);
  33. }
  34. for(int n : square_numbers)
  35. cout << n << " ";
  36.  
  37. cout << endl;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement