ZOJ 1284 Perfection

查看原题

题意

如果一个数的所有真约数等于它本身,即完全数
如果大于它本身,则abundant
否则deficient
注意输入输出,要求对齐

思路

代码

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int temp[1000];
int isPerfect(int n){
    int sum=0;
    for(int i=1;i<=n/2;i++){
        if(n%i==0){
            sum+=i;
        }
    }
    if(sum==n){
        return 1;
    }
    else if(sum>n){
        return 2;
    }
    else{
        return 0;
    }
}
int main(int argc, char *argv[])
{
    int step=0;
    while(cin>>temp[++step]){
        if(temp[step]==0){
            break;
        }
    }
    cout<<"PERFECTION OUTPUT"<<endl;
    for(int i=1;i<=step;i++){
        if(temp[i]==0){
            cout<<"END OF OUTPUT"<<endl;
            break;
        }
        printf("%5d  ",temp[i]);//注意这里
        if(isPerfect(temp[i])==1){
            cout<<"PERFECT"<<endl;
        } else if(isPerfect(temp[i])==2){
            cout<<"ABUNDANT"<<endl;
        }else{
            cout<<"DEFICIENT"<<endl;
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值