fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int n, numar;
  7. char sir[5];
  8.  
  9. int main() {
  10. cin >> n;
  11. cin.getline(sir,5);
  12. for (int i = 1; i <= n; ++i){
  13. numar = 0;
  14. cin.getline(sir,5);
  15. int check = 0;
  16. for (int j = 0; j < 4; ++j){
  17. if (sir[j] > 0 && check == 0)
  18. check = 1;
  19. if (check == 1){
  20. numar += (int)(sir[j] - '0');
  21. numar *= 10;
  22. }
  23. }
  24. numar /= 10;
  25. int nr_sqrt = (int)sqrt(numar);
  26. if (nr_sqrt * nr_sqrt != numar)
  27. cout << -1 << '\n';
  28. else
  29. cout << sqrt(numar) << ' ' << 0 << '\n';
  30. }
  31. }
  32.  
Success #stdin #stdout 0s 5316KB
stdin
5
0001
1001
1000
4900
2025
stdout
1 0
-1
-1
70 0
45 0