ValerianBenchea

Palindroame tip munte, 12

Jan 21st, 2020
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int o, c, nrc, x;
  7.     for(unsigned long long p=121; p<=999999999999; p++)
  8.     {
  9.         x=p;
  10.         o=0;
  11.         nrc=0;
  12.         while(x!=0)
  13.         {
  14.             c=x%10;
  15.             nrc++;
  16.             o=o*10+c;
  17.             x/=10;
  18.         }
  19.         if(p==o && nrc%2==1)
  20.         {
  21.             //cout<<o<<" ";
  22.             c=o%10;
  23.             o/=10;
  24.             bool ok=true;
  25.             for(int i=2; i<=nrc/2+1 && ok; i++)
  26.             {
  27.                 if(c>=o%10)
  28.                     ok=false;
  29.                 c=o%10;
  30.                 o/=10;
  31.             }
  32.             if(ok==true)
  33.                 cout<<p<<" ";
  34.         }
  35.     }
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment