fork(1) download
  1. #include <iostream>
  2. #include<math.h>
  3. using namespace std;
  4. int odwracanie(int x, int lic, int a, int j) {
  5. x = (int) floor(lic / a)*j + x;
  6. lic = lic % a;
  7. a=a/10;
  8. j = j * 10;
  9. if (a<1) return x;
  10. else odwracanie(x, lic, a, j);
  11. }
  12. int main()
  13. {
  14. int lic, ile, cil,x;
  15. float a;
  16. cin >> ile;
  17. for (int i = 0; i < ile; i++) {
  18. x = 0;
  19. cin >> lic;
  20. a = floor(log10(lic));
  21. a = pow(10, a);
  22. while (true) {
  23. cil = odwracanie(0, lic, a, 1);
  24. if (cil == lic) {
  25. cout << lic << ' ' << x << endl;
  26. break;
  27. }
  28. else {
  29. x++;
  30. lic = cil + lic;
  31. }
  32. }
  33. }
  34. return(0);
  35. }
Time limit exceeded #stdin #stdout 5s 16064KB
stdin
Standard input is empty
stdout
Standard output is empty