题目:http://acm.hdu.edu.cn/showproblem.php?pid=1271
数学知识:不会做。看的题解。。为了下一章。。悲剧。
# include<stdio.h>
# include<stdlib.h>
int cmp(const void *a,const void *b)
{
return *(int *)a - *(int *)b;
}
int main()
{
int n,a,b,c,count,k,s[100],i;
while(scanf("%d",&n)!=EOF && n)
{
count=0;
for(k=1;k<=n;k*=10)
{
c=(n/k)/11;
b=n/k-c*11;
if((b!=0 || c!=0) && b<10)
{
a=(n-b*k-c*11*k)/2;
if(2*a+b*k+c*11*k==n)
{
count++;
s[count]=a+b*k+c*10*k;
}
}
b--;
if((b!=0 || c!=0) && b>=0)
{
a=(n-b*k-c*11*k)/2;
if(2*a+b*k+c*11*k==n)
{
count++;
s[count]=a+b*k+c*10*k;
}
}
}
if(count==0) printf("No solution.\n");
else
{
qsort(s+1,count,sizeof(s[1]),cmp);
printf("%d",s[1]);
for(i=2;i<=count;i++)
{
if(s[i]!=s[i-1])
printf(" %d",s[i]);
}
printf("\n");
}
}
return 0;
}