hdu1323

题意为:输入一个数求它的因子和,并判断因子和与该数的大小关系

如果因子和大于该数输出DEFICIENT

如果因子和等于该数输出PERFECT

如果因子和小于该数输出ABUNDANT

需要注意的就是格式问题!!!

#include<stdio.h>
#include<math.h>
#include<string>
#include<string.h>
#include<cstring>
#include<string.h>
#include<algorithm>
#include<iomanip>
#include<iostream>
using namespace std;
int main() {
	int n, sum;
	char str1[8] = "PERFECT", st2[9] = "ABUNDANT", str3[10] = "DEFICIENT";
	cout << "PERFECTION OUTPUT" << endl;
	while(scanf("%d", &n) != EOF && n){
		sum = 0;
		for(int i=1; i<n; ++i){
			if(sum > n){
				cout << setw(5) << n << "  "<< st2 << endl;
				break;
			}
			if(n%i == 0)
				sum += i;
		}
		if(sum == n)
			cout << setw(5) << n << "  " << str1 << endl;
		else if(sum < n)
			cout << setw(5) << n << "  " << str3 << endl;
	}
	cout << "END OF OUTPUT" << endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值