fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int odwr (int li);
  8. int ile_cyfr(int l);
  9.  
  10. int t,j,n,x, odwrocona;
  11. float y,a;
  12. int liczba;
  13.  
  14. int main()
  15. {
  16. cout<< "wpisz ilosc liczb do testow"<<endl;
  17. cin>>t;
  18.  
  19. for(int i=0;i<t;i++)
  20. {
  21. cin>> liczba;
  22.  
  23. for(j=0; liczba!=odwr(liczba); j++)
  24. {
  25. liczba=liczba+odwrocona;
  26. }
  27.  
  28. cout<<liczba<<" "<<j<<endl;
  29. }
  30. return 0;
  31. }
  32.  
  33. int ile_cyfr(int l)
  34. {
  35. ostringstream ss;
  36. ss<<l;
  37. string str= ss.str();
  38. int c= str.size();
  39. return c;
  40. }
  41.  
  42. int odwr (int li)
  43. {
  44. n=ile_cyfr(liczba);
  45.  
  46. int*t;
  47. t=new int[n];
  48.  
  49. for(int i=1; i<=n;i++)
  50. {
  51. x=li/pow(10,n-i);
  52. t[i-1]=x;
  53. y=x* pow(10,n-i);
  54. li=li-y;
  55. }
  56. odwrocona=0;
  57.  
  58. for (int k=1; k<=n; k++)
  59. {
  60. a= t[n-k]* pow(10,n-k);
  61. odwrocona= odwrocona + a;
  62. }
  63.  
  64. delete [] t;
  65. return odwrocona;
  66. }
  67.  
  68.  
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
wpisz ilosc liczb do testow