Submitted solution with Run Time = 0.010
#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<int> nos;
int t,sum,i;
cin>>t;
while(t!=0)
{
nos.push_back(t);
cin>>t;
}
nos.push_back(0);
t=0;
sum=1;
cout<<"PERFECTION OUTPUT"<<endl;
while(nos[t]!=0)
{
if(nos[t] == 1)
{
cout<<" "<<nos[t]<<" ";
// printf("%5d ",nos[t]);
cout<<"DEFICIENT"<<endl;
t++;
}
else
{
for(i=2;i<nos[t];i++)
{
if(nos[t]%i==0)
{
sum=sum+i;
}
}
if(nos[t]/10==0)
cout<<" "<<nos[t]<<" ";
else if(nos[t]/100==0)
cout<<" "<<nos[t]<<" ";
else if(nos[t]/1000==0)
cout<<" "<<nos[t]<<" ";
else if(nos[t]/10000==0)
cout<<" "<<nos[t]<<" ";
else if(nos[t]/100000==0)
cout<<nos[t]<<" ";
// printf("%5d ",nos[t]);
if(sum==nos[t])
{
cout<<"PERFECT"<<endl;
}
else if(sum>nos[t])
{
cout<<"ABUNDANT"<<endl;
}
else if(sum<nos[t])
{
cout<<"DEFICIENT"<<endl;
}
sum=1;
t++;
}
}
cout<<"END OF OUTPUT"<<endl;
//system("pause");
return 0;
}
Comment for better algorithm.
Wednesday, February 6, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment