【模拟枚举】水仙花数题解
2026-07-03 15:01:35
发布于:四川
2阅读
0回复
0点赞
题解来咯,记得关注我哟!
# include <bits/stdc++.h>
using namespace std;
bool func(int n){
int t=n,sum=0;
while(t!=0){
int h=pow((t%10),3);
sum+=h;
t/=10;
}
if(sum==n) return true;
else return false;
}
int main(){
for(int i=100;i<=999;i++){
if(func(i)==true) cout<<i<<endl;
}
return 0;
}
还没完,看看这个嘻嘻:
# include <bits/stdc++.h>
using namespace std;
int main(){
cout<<153<<endl<<370<<endl<<371<<endl<<407;
return 0;
}
这里空空如也








有帮助,赞一个