SHARE
TWEET

Untitled

a guest Jun 12th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8. #include <iostream>
  9. #include <cstdlib>
  10. #include <sstream>
  11. using namespace std;
  12.  
  13. string odwrotna(string liczba){
  14.     string wynik;
  15.     for(int i = 0; i < liczba.length(); i++){
  16.         wynik.insert(0, liczba.substr(i, 1));
  17.     }
  18.     return wynik;
  19. }
  20.  
  21. string zamiana_na_stringa(int liczba){
  22.    
  23.     string wynik;
  24.     ostringstream ss;
  25.     ss << liczba;
  26.     wynik = ss.str();
  27.     ss.clear();
  28.     ss.str(string());
  29.     return wynik;
  30. }
  31.  
  32.  
  33. bool palindrom(string a){
  34.    
  35.     for(int i = 0; i < a.length() / 2 + 1; i++){
  36.        
  37.         if(a.at(i) != a.at(a.length() - 1 - i)){
  38.             return false;
  39.         }
  40.        
  41.     }
  42.     return true;
  43. }
  44.  
  45. int main() {
  46.     int t, n, ile = 0;
  47.     string tmp;
  48.     cin >> t;
  49.     for(int i = 0; i < t; i++){
  50.         int n;
  51.         cin >> n;
  52.         while(palindrom(zamiana_na_stringa(n)) == 0){
  53.             ile++;
  54.             tmp = odwrotna(zamiana_na_stringa(n));
  55.             n += atoi(tmp.c_str());
  56.         }
  57.         cout << n << " " << ile << endl;
  58.         ile = 0;
  59.     }
  60.     return 0;
  61.    
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top