382 - Perfection

Moderator: Board moderators

Learning poster
Posts: 90
Joined: Mon Feb 16, 2004 8:53 pm
Location: Bangalore INDIA
Format counts: the echoed integers should be right justified within the first 5 spaces of the output line, followed by two blank spaces, followed by the description of the integer. The final line of output should read END OF OUTPUT.
if u can think of it .. u can do it in software.

efr_shovo
New poster
Posts: 38
Joined: Wed Sep 22, 2004 9:09 am
It is My Resolve Code.But Still P.E

#include<stdio.h>

long count,sum,n[100],d,mod,m,z;

int input()
{
int i=0,f;
do
{
scanf("%d",&n);
f=n;
i++;
}while(f!=0);
return i;
}

void space(int j)
{
if(n[j]<10)
printf(" ");
if(n[j]>=10&&n[j]<100)
printf(" ");
if(n[j]>=100&&n[j]<1000)
printf(" ");
if(n[j]>=1000&&n[j]<10000)
printf(" ");
if(n[j]>10000)
printf(" ");
}

void main()
{
int i=0;
z=input();
if(z>1&&z<100)
{
printf("PERFECTION OUTPUT\n");
while(1)
{
if(n>60000)
break;
if(n==0)
break;
d=n/2;
for(count=1;count<=d;count++)
{
mod=n%count;
if(mod==0)
sum=sum+count;
}
space(i);
if(sum>n)
printf("%ld ABUNDANT\n",n);
else
if(sum==n)
printf("%ld PERFECT\n",n);
else
printf("%ld DEFICIENT\n",n[i]);
sum=0;
i++;
}
printf("END OF OUTPUT");
}
}

Learning poster
Posts: 90
Joined: Mon Feb 16, 2004 8:53 pm
Location: Bangalore INDIA
there are easier ways to format..
[c]
#include<stdio.h>

long count,sum,n[100],d,mod,m,z;

int input()
{
int i=0,f;
do
{
scanf("%d",&n);
f=n;
i++;
}while(f!=0);
return i;
}

void main()
{
int i=0;
z=input();
if(z>1&&z<100)
{
printf("PERFECTION OUTPUT\n");
while(1)
{
if(n>60000)
break;
if(n==0)
break;
d=n/2;
for(count=1;count<=d;count++)
{
mod=n%count;
if(mod==0)
sum=sum+count;
}

if(sum>n)
printf("%5ld ABUNDANT\n",n);
else
if(sum==n)
printf("%5ld PERFECT\n",n);
else
printf("%5ld DEFICIENT\n",n[i]);
sum=0;
i++;
}
printf("END OF OUTPUT\n");
}
}[/c]
if u can think of it .. u can do it in software.

jaracz
Learning poster
Posts: 79
Joined: Sun Sep 05, 2004 3:54 pm
Location: Poland

382

hi guys!

It is necessity to read in input to array?

It is possible that input may exceed 100 and then program shouldn't print anything??

keep it real!

Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!

Jemerson
Learning poster
Posts: 59
Joined: Mon Feb 02, 2004 11:19 pm
Contact:
I found the mistake, the input is in multiple lines, read all lines and process until find the 0, I don't know if there are empty lines, so.. you'd better take care of this too.

Good Luck
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!

thinker_bd
New poster
Posts: 22
Joined: Thu Jun 09, 2005 1:44 am

PLEASE SAY ME WHAT IS MY WRONG
WHY I GETTING WA. MY CODE IS GIVEN BELOW

Code: Select all

``````#include<stdio.h>
int main()
{
long n,i;
printf("PERFECTION OUTPUT\n");
freopen("328.txt","r",stdin);
while(1)
{
scanf("%d",&n);
if(n==0)
{
printf("END OF OUTPUT\n");
break;
}
long sum;
for(i=1;i<=n/2;i++)
{
if(i==1)sum=1;
else
{
if((n%i)==0)
sum+=i;
}
}

long count =0,p=n;
while(1)
{
if(p==0) break;
p=p/10;
count++;
}

printf("%5d",n);
printf(" "); //2space

if(sum>n)
printf("ABUNDANT\n");

else if(sum==n)
printf("PERFECT\n");

else if(sum<n)
printf("DEFICIENT\n");
}
return 0;
}
``````

neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba
1 is DEFICIENT

mars kaseijin
New poster
Posts: 22
Joined: Mon Sep 19, 2005 4:58 am
Contact:
Greetings thinker_bd,
here are some recommendations:
* avoid file i/o as Judge supplies its own set of inputs.
* try to de-couple the algorithm from point of application. It is cleaner design and more functional.

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

382

i get WA for my code but it passes all the sample test cases

here it is.........

Code: Select all

``````
DELETED after AC
``````
Last edited by abhi on Wed Jan 25, 2006 3:18 pm, edited 1 time in total.

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea
I don't think your program print "END OF OUTPUT" at the end of output..

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm
oops!!! silly me ......

athlon19831
New poster
Posts: 20
Joined: Thu Jan 19, 2006 2:32 pm

382 WA

i don't know why i got WA instead of AC.
my code following:
#include <iostream>
using namespace std;
#include <cstring>
#include <cstdio>
#include <cmath>
int main(int argc, char* argv[])
{
char str[1000];
long copy[110];
long s[110];
long i,j,k,l,sum,val,i_save,j_copy;
//bool flag;
for(i=0;i<100;i++)
{
s=0;
}
gets(str);
l=strlen(str);
sum=0;val=10;j=0;
for(i=0;i<l;i++)
{
if(str>='0'&&str<='9')
{
sum=sum*val+int(str)-48;
}
else
{
copy[j]=sum;
j++;
sum=0;
}
if(copy[j-1]=='0')
break;
}
j_copy=j;
for(i=0;i<j_copy;i++)
{
i_save=i;

for(j=2;j<=int(sqrt(copy));j++)
{
if(copy%j==0)
{
i_save=copy/j;
s=s+i_save+j;
}
}
s=s[i]+1;

}

cout<<"PERFECTION OUTPUT"<<endl;
for(i=0;i<j_copy;i++)
{
if(s[i]==copy[i])
{
printf("%5d",copy[i]);
cout<<" PERFECT"<<endl;
}
else if(s[i]<copy[i])
{
printf("%5d",copy[i]);
cout<<" DEFICIENT"<<endl;
}
else
{
printf("%5d",copy[i]);
cout<<" ABUNDANT"<<endl;
}
}
cout<<"END OF OUTPUT"<<endl;

return 0;
}

athlon19831
New poster
Posts: 20
Joined: Thu Jan 19, 2006 2:32 pm

382 WA pls give me some test cases

382 WA pls give me some test cases

raygun
New poster
Posts: 2
Joined: Tue May 09, 2006 3:04 am

Re: 382 WA

I noticed that you have a presentation error - there are supposed to be two spaces. Even if you fix the program bug, you'll still miss out.

Code: Select all

``````	gets(str);
l=strlen(str);
sum=0;val=10;j=0;
for(i=0;i<l;i++)
{
if(str[i]>='0'&&str[i]<='9')
{
sum=sum*val+int(str[i])-48;
}
else
{
copy[j]=sum;
j++;
sum=0;
}
if(copy[j-1]=='0')
break;
}
``````
This is the first problem right here - you assume the input is on one line. Also, the implementation in question chops off the last integer on that line as well since it doesn't even check the null character at the end to see if the number needs to be added.

Code: Select all

``````s[i]=s[i]+1;
``````
This is the second problem - it incorrectly makes 1 a perfect number.