POJ 2719
1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 int dight[9]; 5 int _pow(int m,int n); 6 int main(){ 7 //freopen("test.txt","r",stdin); 8 int i; 9 int num; 10 dight[0] = 0; 11 dight[1] = 1; 12 for(i = 2; i < 9 ; i++) 13 { 14 dight[i] = _pow(10,i-1) + dight[i-1] + 8*dight[i-1]; 15 } 16 while(cin>>num){ 17 if(num == 0) 18 break; 19 int j; 20 int k = 0; 21 int temp; 22 temp = num; 23 int sum = 0; 24 while(temp) 25 { 26 j = temp%10; 27 temp /= 10; 28 if(j > 4) 29 { 30 sum += _pow(10,k); 31 sum += dight[k]*(j-1); 32 } 33 else 34 sum += dight[k]*j; 35 k++; 36 } 37 cout<<num<<": "<<num-sum<<endl; 38 } 39 system("pause"); 40 } 41 int _pow(int m,int n) 42 { 43 if(n == 0) 44 return 1; 45 else if(1 == n) 46 return m; 47 else 48 return m*_pow(m,n-1); 49 }