#include <iostream>
#include <stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv)
{
//输入n
int n=0;
scanf("%d",&n);
//暴力查找符合条件的数
int tag=0;//假设找不到
for(int i=1;i<=n;i++)
{
int temp=i;
int sum=0;
while(temp!=0)
{
sum+=temp%10;//加剩下的最后一位
temp/=10;//去掉最后一位
}
sum+=i;
if(sum==n)
{
printf("%d",i);
tag=1;
break;
}
}
if(tag==0)
printf("cant find");
return 0;
}
第三章例题 最小生成元——逐位的写法
最新推荐文章于 2021-12-07 11:22:38 发布