せいしゅん404 • 4年前
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[205],b[205];
bool cmp(int a,int b){
return a>b;
}
//次方求和
int sum(int n,int k){
int x=0;
do{
x+=pow(n%10,k);
n/=10;
}while(n);
return x;
}
int main(void){
// freopen("ghillie.in","r",stdin);
// freopen("ghillie.out","w",stdout);
int n,*p,*q,k=2,count=0;
//获取输入
cin>>n;
p=a;
while(scanf("%d",p)!=EOF){
p++;
count++;
}
//进行N轮计算 注意k是从2开始的,所以n要加1
while(k<=n+1){
//每个数进行次方求和计算并存入b的内存中
p=a;
q=b;
for(int i=0;i<count;i++){
*q=sum(*p,k);
p++;
q++;
}
q=b;//存完后重新指向b的开始
//比较是否相等,相等则清零
for(int i=0;i<count;i++){
p=a;
for(int j=0;j<count;j++){
if(*p==*q) *p=0;
p++;
}
q++;
}
//从大到小排序
sort(a,a+count,cmp);
//剩下的数的个数
p=a;
for(int i=0;i<count;i++){
if(*p==0){
count=i;
break;
}
p++;
}
k++;
}
//倒序输出
p=&a[count-1];
for(int i=count-1;i>=0;i--){
cout<<*p<<" ";
p--;
}
cout<<endl;
return 0;
}
评论:
请先登录,才能进行评论