HDU 1271

这题做了好久、....

理解别人的代码都理解了好久!!!太弱太弱、

 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cmath>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,a,b,c,count,k,s[100],i;
 8     while(cin >> n && n){
 9         count=0;
10         for(int k=1;k<=n;k*=10){
11             c=(n/k)/11;
12             b=n/k-c*11;
13             if((b!=0||c!=0)&&b<10)
14             {
15                 a=(n-b*k-c*11*k)/2;
16                 if(2*a+b*k+c*11*k==n)
17                     s[count++]=a+b*k+c*10*k;
18             }
19             b--;
20             if((b!=0||c!=0)&&b>=0)
21             {
22                 a=(n-b*k-c*11*k)/2;
23                 if(2*a+b*k+c*11*k==n)
24                     s[count++]=a+b*k+c*10*k;
25             }
26         }
27         if(count==0)    cout << "No solution." << endl;
28         else{
29             sort(s,s+count);
30             cout << s[0];
31             for(int i=1;i<count;++i)
32                 if(s[i]!=s[i-1])
33                 cout << " " << s[i];
34             cout << endl;    
35         } 
36     }
37     return 0;
38 }
原文地址:https://www.cnblogs.com/sasuke-/p/5156139.html