jainharshit

Untitled

Dec 21st, 2011
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. using namespace std;
  4. int length(int n)
  5. {
  6.         int len=0;
  7.         while(n!=0)
  8.         {
  9.                 len++;
  10.                 n=n/10;
  11.         }
  12.         return len;
  13. }
  14. int power(int a,int b)
  15. {
  16.         int val=1;
  17.         for(int i=0;i<b;i++)
  18.         {
  19.                 val=val*a;
  20.         }
  21.         return val;
  22. }
  23. int main()
  24. {
  25.     int sol=0;
  26.     int num;
  27.     cin>>num;
  28.     int val=length(num);
  29.     int array[val];
  30.     int n=num;
  31.     int index;
  32.     for(index=0;n!=0;index++)
  33.     {
  34.        array[index]=n%10;
  35.        n=n/10;
  36.     }
  37.     /*for(int i=0;i<index;i++)
  38.     {
  39.             cout<<array[i]<<endl;
  40.     }*/
  41.     for(int i=0;i<(val/2);i++)
  42.     {
  43.         int temp=array[i];
  44.         array[i]=array[val-i-1];
  45.         array[val-i-1]=temp;
  46.  
  47.     }
  48.     int size = val;
  49.     for(int k = 0; k < size; k ++)
  50.     {
  51.             //cout<<endl<<"k="<<k<<endl;
  52.             for(int i = 0; i < size-k; i ++)
  53.             {
  54.                     int no = 0;
  55.                     for(int j = k,l = i;j >= 0; j --, l ++)
  56.                     {
  57.  
  58.                             no=no+array[l]*power(10,j);
  59.                             //cout<<"(val="<<int(pow(10,j))<<")";
  60.                     }
  61.                     if( no % 8 ==0 && length(no)==k+1)
  62.                     {
  63.                             sol++;
  64.                     }
  65.                     //cout<<no<<endl;
  66.             }
  67.     }
  68.    
  69.     cout<<sol;
  70. }
Add Comment
Please, Sign In to add comment