![:)](./images/smilies/icon_smile.gif)
382 - Perfection
Moderator: Board moderators
Yes...
So many thank's I got Accepted... ![:)](./images/smilies/icon_smile.gif)
![:)](./images/smilies/icon_smile.gif)
try_try_try_try_&&&_try@try.com
This may be the address of success.
This may be the address of success.
Re: 382 WA
I doubt the judge's test case doesn't have 0 at end. Can anyone confirm this?
Thanks
Many thanks to CSEDU_1323
I was getting WA bcoz i was printing "1" as perfect![:oops:](./images/smilies/icon_redface.gif)
![8)](./images/smilies/icon_cool.gif)
I was getting WA bcoz i was printing "1" as perfect
![:oops:](./images/smilies/icon_redface.gif)
I am not totally useless, because I can still be used as a bad example ![:P](./images/smilies/icon_razz.gif)
![:P](./images/smilies/icon_razz.gif)
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;
}
#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;
}
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.
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.
-
- 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;
}
Re: 382 WA
Use printf("%5d PERFECT\n", n), et cetera.
-
- 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...
i correct that..printf("%5d DEFICIENT\n", n); but still getting a WA.
i don't see any problem there..then why still WA???
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???
-
- 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 lineToCode: Select all
count = 1;
andCode: Select all
count =0;
ToCode: Select all
for(i=2;i<=n/2;i++)
another thing u must have to change.......Code: Select all
for(i=1;i<=n/2;i++)
change it toCode: 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);
That is printf("%5d##DEFICIENT\n", n);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);
here # means space
And after ACC PLZ remove ur code....![]()
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]
#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]
-
- 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....
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 ..... ![:x](./images/smilies/icon_mad.gif)
![:x](./images/smilies/icon_mad.gif)
-
- New poster
- Posts: 6
- Joined: Thu Sep 23, 2010 1:50 pm
- Location: Dhaka, Bangladesh
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;
}
382 WA
why wrong answer please help me
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;
}
-
- New poster
- Posts: 1
- Joined: Sat Jul 02, 2011 5:59 pm
Why Presentation Error on 382???
Hey Please help !
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;
}
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;
}