fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6. bool spr(string liczba,int l);
  7. string zmiana(string wyraz);
  8. int ile,p;
  9. bool wynik;
  10. string liczba;
  11.  
  12. int main()
  13. {
  14. cin>>ile;
  15. for (int i=0; i<ile; i++)
  16. {
  17. p=0;
  18. cin>>liczba;
  19. int l=liczba.length();
  20. wynik=spr(liczba,l);
  21. while (wynik==false)
  22. {
  23. liczba=zmiana(liczba);
  24. l=liczba.length();
  25. wynik=spr(liczba,l);
  26. p++;
  27. }
  28.  
  29. cout<<liczba<<" "<<p<<endl;
  30.  
  31. }
  32. return 0;
  33. }
  34.  
  35.  
  36. bool spr(string liczba,int l)
  37. {
  38. bool flaga=false;
  39. int i=0;
  40. int j=l-1;
  41. while (liczba[i]==liczba[j])
  42. {
  43. i++;
  44. j--;
  45. if (i>=j)
  46. {
  47. flaga=true;
  48. return flaga;
  49. break;
  50. }
  51.  
  52. }
  53. return flaga;
  54. }
  55.  
  56. string zmiana(string wyraz)
  57. {
  58. int d=wyraz.length();
  59.  
  60.  
  61. string nowy;
  62. for (int i=d-1; i>=0; i--)
  63. {
  64. nowy=nowy+wyraz[i];
  65. }
  66. int n = atoi(wyraz.c_str());
  67. int m = atoi(nowy.c_str());
  68. int s = m+n;
  69.  
  70.  
  71. int value = s;
  72. string _str = to_string(value);
  73. return _str;
  74.  
  75. }
  76.  
Success #stdin #stdout 0s 16064KB
stdin
3
28
68
5
stdout
121 2
1111 3
5 0