本文章由 WyOJ Shojo 从洛谷专栏拉取,原发布时间为 2021-04-08 16:17:07
思路
输入 $n$ 之后,先求出他的位数,接着让变量 $sum$ 加上 $n$ 每一位的位数方,最后判断一下就可以了。
代码
#include <iostream>
#include <cmath>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
long long n,sum=0,q,len=0;
cin>>n;
q=n;
while(q){\/\/判断位数
++len;
q\/=10;
}
q=n;
while(q){\/\/加上每位的位数方
sum+=(long long)(pow(q%10,len));
q\/=10;
}
cout<<(sum==n?"Armstrong":"Not Armstrong")<<endl;
}
return 0;
十年OI一场空,不开 long long 见祖宗

鲁ICP备2025150228号