标签:show lap sed 数字 problem end tmp include names
一个整数M(10 <= M <= 1000)
输出>= M的最小的水仙花数
99
153
从m开始枚举,直到遇到第一个水仙花数。
1 #include <iostream> 2 using namespace std; 3 int pow(int x,int n) 4 { 5 int ans=1; 6 for(int i=1;i<=n;i++) 7 ans*=x; 8 return ans; 9 } 10 bool is_shui(int n) 11 { 12 int tmp=n; 13 int len=0; 14 int ans=0; 15 while(tmp) 16 { 17 tmp/=10; 18 len++; 19 } 20 tmp=n; 21 while(n) 22 { 23 int t=n%10; 24 n/=10; 25 ans+=pow(t,len); 26 } 27 if(ans==tmp) 28 return true; 29 return false; 30 } 31 int main() 32 { 33 int m; 34 cin>>m; 35 while(!is_shui(m)) 36 m++; 37 cout<<m<<endl; 38 return 0; 39 }
标签:show lap sed 数字 problem end tmp include names
原文地址:http://www.cnblogs.com/onlyli/p/7252496.html