382 - Perfection
Moderator: Board moderators
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");
}
}
#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");
}
}
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]
[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.
382
hi guys!
It is necessity to read in input to array?
Can I read one integer(long) and write answer, then read next and so on and on??
It is possible that input may exceed 100 and then program shouldn't print anything??
w8ing 4reply..thx in advance
It is necessity to read in input to array?
Can I read one integer(long) and write answer, then read next and so on and on??
It is possible that input may exceed 100 and then program shouldn't print anything??
w8ing 4reply..thx in advance
keep it real!
I'm not so sure about this, but i guess your read buffer wont hold about 100 integer like 59999, will it? U'd better increase it and try again.
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
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
Good Luck
UFCG Brazil - Computer Science graduate student
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
http://acm.uva.es/problemset/usersnew.php?user=54806 ... and going up!
-
- New poster
- Posts: 22
- Joined: Thu Jun 09, 2005 1:44 am
PLEASE HELP ME IN 382 , WHY I GETTING WA
PLEASE SAY ME WHAT IS MY WRONG
WHY I GETTING WA. MY CODE IS GIVEN BELOW
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;
}
-
- New poster
- Posts: 22
- Joined: Mon Sep 19, 2005 4:58 am
- Contact:
-
- 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;
}
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;
}
-
- 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
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.
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.
This is the second problem - it incorrectly makes 1 a perfect number.
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;
}
Code: Select all
s[i]=s[i]+1;