fork download
  1. // Zabawne Dodawanie Piotrusia.cpp : Defines the entry point for the console application.
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5. #include <string>
  6. int h = 0;
  7.  
  8. using namespace std;
  9. void palindrome(string b);
  10.  
  11. int main()
  12. {
  13. int count = 0;
  14. string letter;
  15.  
  16. cin >> count;
  17. for (int i = 0; i < count; i++)
  18. {
  19. cin >> letter;
  20. palindrome(letter);
  21. }
  22. return 0;
  23. }
  24.  
  25. void palindrome(string b) //Funkcja sprawdzajaca czy liczba jest polindromem
  26. {
  27. int i, j;
  28.  
  29. for (i = 0, j = b.length() - 1; i < j; i++, j--)
  30. {
  31. if (b[i] != b[j])
  32. break;
  33. }
  34. if (i < j)
  35. {
  36. h++;
  37. int l;
  38. string lpl;
  39. for (l = b.length() - 1; 0 <= l; l--) //Petla zapisywania liczby od tylu
  40. {
  41. lpl += b[l];
  42. }
  43. int q = atoi(b.c_str()); //Liczba podana i zmiana na int
  44. int w = atoi(lpl.c_str()); //Liczba odwrocona i zmiana na int
  45. int e = q + w; //Suma liczb
  46. string mpm = to_string(e); //Konwersja z int na string
  47. palindrome(mpm);
  48. }
  49. else
  50. {
  51. cout << b << " " << h << endl;
  52. h = 0;
  53. }
  54. }
Success #stdin #stdout 0s 4304KB
stdin
3
28
68
5
stdout
121 2
1111 3
5 0