## 382 - Perfection

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am

### Yes...

So many thank's I got Accepted...
try_try_try_try_&&&_try@try.com
This may be the address of success.

WAandAC
New poster
Posts: 4
Joined: Sat Nov 03, 2007 4:32 am

### Re: 382 WA

I doubt the judge's test case doesn't have 0 at end. Can anyone confirm this?

zyxw
New poster
Posts: 24
Joined: Sat Mar 22, 2008 5:49 am
Location: Chennai
Contact:

### Thanks

Many thanks to CSEDU_1323
I was getting WA bcoz i was printing "1" as perfect
I am not totally useless, because I can still be used as a bad example

mhn
New poster
Posts: 4
Joined: Mon Jun 22, 2009 7:05 am

### Re: 382 getting wa

the code seems fine to me..but getting wa..

#include<stdio.h>

int main(){

int a,b,i,sum;

printf("PERFECTION OUTPUT\n");
while(scanf("%d",&a)==1){

sum=0;

if(a==0) {printf("END OF OUTPUT");break;}

else{

for(i=1;i<=a/2;i++){

b=a%i;
if(b==0) sum=sum+i;

}
if(sum==a) printf("%d PERFECT\n",a);
else if(sum<a) printf("%d DEFICIENT\n",a);
else if(sum>a) printf("%d ABUNDANT\n",a);

}

}

return 0;

}

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

### Re: 382 WA

Use [code]...[/code] tags when posting any source code!

Your program improperly formats the output - see the sample output, and read again the "Output" section of problem statement.

And there should be a \n character at the end of output.

etameem
New poster
Posts: 5
Joined: Tue Jul 21, 2009 11:11 am
Location: (CSE, JU) Dhaka,Bangladesh
Contact:

### Re: 382 WA

Code: Select all

``````#include <iostream>
using namespace std;

int main()
{
int n,a,b,i,j=0,k,count=1;

while( cin>>n)

{
count=1;
if(j==0)
cout<<"PERFECTION OUTPUT"<<endl;
if(n==0)
{
cout<<"END OF OUTPUT"<<endl;
break;

}
for(i=2;i<=n/2;i++)
{
if(n%i==0)
count=count+i;
else
continue;

}
if(count==n)
cout<<n<<"  PERFECT"<<endl;

else if (count>n)
cout<<n<<"  ABUNDANT"<<endl;

else
cout<<n<<"  DEFICIENT"<<endl;

j++;
}
return 0;
}

``````
i am getting WA, i know there are some mistakes..but where???? how can i reduce the Space problem in the output.?

mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

### Re: 382 WA

Use printf("%5d PERFECT\n", n), et cetera.

etameem
New poster
Posts: 5
Joined: Tue Jul 21, 2009 11:11 am
Location: (CSE, JU) Dhaka,Bangladesh
Contact:

### Re: 382 WA

this is my code now...

Code: Select all

``````#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
int n,a,b,i,j=0,k,count=1;

while( cin>>n)

{
count=1;
if(j==0)
cout<<"PERFECTION OUTPUT"<<endl;
if(n==0)
{
cout<<"END OF OUTPUT"<<endl;
break;

}
for(i=2;i<=n/2;i++)
{
if(n%i==0)
count=count+i;
else
continue;

}
if(count==n)
//cout<<n<<"  PERFECT"<<endl;
printf("%5d PERFECT\n", n);

else if (count>n)
//cout<<n<<"  ABUNDANT"<<endl;
printf("%5d ABUNDANT\n", n);

else
//cout<<n<<"  DEFICIENT"<<endl;
printf("%5d DEFICIENT\n", n);

j++;
}
return 0;
}

``````

i correct that..printf("%5d DEFICIENT\n", n); but still getting a WA.
i don't see any problem there..then why still WA???

saiful_sust
Learning poster
Posts: 97
Joined: Fri Aug 22, 2008 10:18 pm
Location: CSE.SUST.SYLHET

### Re: 382 WA

In ur code there r two wrong thing

no one :
chang this line

Code: Select all

``````count = 1;
``````
To

Code: Select all

``````count =0;
``````
and

Code: Select all

``````for(i=2;i<=n/2;i++)
``````
To

Code: Select all

``````for(i=1;i<=n/2;i++)
``````
another thing u must have to change.......

Code: Select all

``````if(count==n)
//cout<<n<<"  PERFECT"<<endl;
printf("%5d PERFECT\n", n);

else if (count>n)
//cout<<n<<"  ABUNDANT"<<endl;
printf("%5d ABUNDANT\n", n);

else
//cout<<n<<"  DEFICIENT"<<endl;
printf("%5d DEFICIENT\n", n);
``````
change it to

Code: Select all

``````if(count==n)
printf("%5d  PERFECT\n", n);

else if (count>n)
printf("%5d  ABUNDANT\n", n);

else
printf("%5d  DEFICIENT\n", n);

``````
That is printf("%5d##DEFICIENT\n", n);
here # means space

And after ACC PLZ remove ur code....

rubelreza
New poster
Posts: 2
Joined: Fri Jun 26, 2009 12:08 am

### Re: 382 WA

viya, i m not understanding why 1 is deficient????******

New poster
Posts: 3
Joined: Mon Apr 05, 2010 8:09 pm

### Re: 382 WA

//[c]

#include<stdio.h>

int main()
{
long int n;

long int i=0,sum;

printf("PERFECTION OUTPUT\n");

while(scanf("%ld",&n))
{

sum=0;

if(n==0)
break;

for(i=1;i<=n/2;i++)
{
if((n%i)==0)
sum+=i;

}
if(sum==n)
printf("%5ld PERFECT\n",n);
else if(sum<n)
printf("%5ld DEFICIENT\n",n);
else
printf("%5ld ABUDANT\n",n);
}
printf("END OF OUTPUT\n");
return 0;

}//[c]

shaon_cse_cu08
New poster
Posts: 50
Joined: Tue May 25, 2010 9:10 am
Contact:

### Re: 382 WA

U r taking one input and processing that input one at a time....
But the problem is about inputting a set of input... And processing them....
The line "PERFECTION OUTPU" Will be on top of the output set.... Not Avobe ur input set....

U should slightly change ur program by taking all the input in an array... And testing each case of the array element....
I'll keep holding on...Until the walls come tumbling down...And freedom is all around .....

anik.bit0104
New poster
Posts: 6
Joined: Thu Sep 23, 2010 1:50 pm

### Re: 382 WA

Code: Select all

``````#include <iostream>
#include <stdio.h>
#include <cmath>
using namespace std;

//functions
void listOfDivisors(unsigned int givenNum);
int caseCounter=0;
unsigned int isPerfectOrAbundOrDef(unsigned int l);
string numberOfSpaces(unsigned int givenNum);

unsigned int arrayOfDivisors[20000];

int main()
{
unsigned int givenNum;

while (scanf("%d",&givenNum)==1)
{
if (givenNum==0)
{
cout<<"END OF OUTPUT";
break;
}

listOfDivisors(givenNum);

unsigned int result=isPerfectOrAbundOrDef(givenNum);

if(caseCounter==0) cout<<"PERFECTION OUTPUT"<<endl;
caseCounter++;
if (result==0) cout<< numberOfSpaces(givenNum) << givenNum <<"  PERFECT"<<endl;
else if (result==1) cout << numberOfSpaces(givenNum) << givenNum <<"  ABUNDANT"<<endl;
else cout << numberOfSpaces(givenNum) <<givenNum<<"  DEFICIENT"<<endl;

for (unsigned int j=0;j<20000 ;j++ )
{
arrayOfDivisors[j]=0;
}

}

return 0;
}

unsigned int isPerfectOrAbundOrDef(unsigned int l)
{

unsigned int sumOfDivisors=0;

for (unsigned int i=0;i<20000 ;i++ )
{
sumOfDivisors=sumOfDivisors+arrayOfDivisors[i];
}

if (sumOfDivisors>l) return 1;
else if (sumOfDivisors==l) return 0;
else return -1;
}

void listOfDivisors(unsigned int givenNum)
{

unsigned int i=0;

for (unsigned int l=1; l<= int(givenNum/2);l++)
{

if ((givenNum%l)==0)
{
arrayOfDivisors[i]=l;
i++;
}

}

}

string numberOfSpaces(unsigned int givenNum)
{

string numOfSpaces;

unsigned int i=ceil(log10(givenNum));

if(i==5)      numOfSpaces=numOfSpaces+"";
else if(i==4) numOfSpaces=numOfSpaces+" ";
else if(i==3) numOfSpaces=numOfSpaces+"  ";
else if(i==2) numOfSpaces=numOfSpaces+"   ";
else if(i==1) numOfSpaces=numOfSpaces+"    ";
return numOfSpaces;

}
``````
can anyone tell me, what's the f***ing problem with this code? driving me damn crazy..

New poster
Posts: 44
Joined: Thu Jul 22, 2010 9:42 am

### 382 WA

Code: Select all

``````#include<stdio.h>
#include<string.h>
#include<stdlib.h>
long i, num,sum;
int list[100];
char input[50000];

int main() {

gets(input);
char *p;
printf("PERFECTION OUTPUT\n");
p = strtok(input," ");
while( p != NULL )
{
num = atol( p);
if(num == 0)
break;
sum = 0;
for( i = 1; i <= num/2; i++) {
if( num %i == 0) {
sum = sum + i;
}
}

if(num == sum) {
printf("%5d  PERFECT\n", num);
}
else if( num < sum) {
printf("%5d  ABUNDANT\n", num);
}
else if( num > sum) {
printf("%5d  DEFICIENT\n", num);
}
p = strtok(NULL," ");
}
printf("END OF OUTPUT\n");

return 0;
}

``````

zishaniuc1745026197
New poster
Posts: 1
Joined: Sat Jul 02, 2011 5:59 pm

### Why Presentation Error on 382???

Presentation error why?
#include<stdio.h>
int main()
{
long int num,i,sum;
printf("PERFECTION OUTPUT\n");
while(scanf("%ld",&num)==1)
{
if(num==0)
{
printf("END OF OUTPUT\n");
break;
}
else
{
sum=0;
for(i=1;i<num;i++)
{
if(num%i==0) sum+=i;
}
if(sum==num) printf("%5ld PERFECT\n",num);
else if(sum<num) printf("%5ld DEFICIENT\n",num);
if(sum>num) printf("%5ld ABUNDANT\n",num);
}
}
return 0;
}