fork(2) download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int liczbaTestow, dlugoscLiczby, liczbaIteracji;
  7. string liczba, liczbaOdwrocona;
  8. bool palindrom = false;
  9.  
  10. bool CzyPalindorm(string dana)
  11. {
  12. dlugoscLiczby = dana.length();
  13.  
  14. if (dlugoscLiczby == 1)
  15. return true;
  16. else
  17. for(int i=0; i<dlugoscLiczby/2;i++)
  18. {
  19. if(dana[i]!=dana[dlugoscLiczby-1-i])
  20. return false;
  21. }
  22. return true;
  23. }
  24.  
  25. int main()
  26. {
  27. cin >> liczbaTestow;
  28.  
  29. for (int j = 0; j < liczbaTestow; j++)
  30. {
  31. cin >> liczba;
  32. liczbaOdwrocona=liczba;
  33. liczbaIteracji = 0;
  34.  
  35. while(CzyPalindorm(liczba)!= true)
  36. {
  37. for(int i = 0;i<dlugoscLiczby;i++)
  38. liczbaOdwrocona[i]=liczba[dlugoscLiczby-1-i];
  39. liczba = to_string(stoi(liczba)+stoi(liczbaOdwrocona));
  40. liczbaIteracji++;
  41. }
  42. cout << stoi(liczba) << " " << liczbaIteracji;
  43.  
  44. if (j!=liczbaTestow-1)
  45. {
  46. cout << endl;
  47. }
  48.  
  49. }
  50.  
  51. return 0;
  52. }
  53.  
Success #stdin #stdout 0s 4888KB
stdin
Standard input is empty
stdout
Standard output is empty