Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <sstream>
- using namespace std;
- bool pal(int x)
- {
- stringstream cnv;
- string t;
- cnv<<x;
- cnv>>t;
- string s=t;
- reverse(&s[0],&s[0]+s.length());
- return (s==t);
- }
- int main()
- {
- int ans=0;
- for(int i=100000;i<1000000;++i)
- {
- if(i%(int)1e6==0)
- {
- cerr<<"R:"<<i<<" with:"<<ans<<endl;
- }
- int current=i;
- while(current>=10)
- {
- if(pal(current))
- {
- ans++;
- break;
- }
- int sum=0;
- while(current)
- {
- sum+=current%10;
- current/=10;
- }
- current=sum;
- }
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement