自冥数判断题解
2026-04-08 17:09:49
发布于:浙江
2阅读
0回复
0点赞
老师版:
#include<bits/stdc++.h>
using namespace std;
bool isarmstrong(int num) {
int s=num;//保存原数
int n=0,temp=num;
while(temp>0) {
temp/=10;
n++;
}
temp=s;
int sum=0;
while(temp>0) {
int digit=temp%10;
sum+=pow(digit,n);
temp/=10;
}
return sum==s;
}
int main()
{
int m;
cin>>m;
for(int i=0;i<m;i++) {
int x;
cin>>x;
if(isarmstrong(x)) {
cout<<"T"<<endl;
}else{
cout<<"F"<<endl;
}
}
return 0;
}
这里空空如也







有帮助,赞一个