Case #1: 1 is a Happy number.
Case #2: 2 is an Unhappy number.
Case #3: 3 is an Unhappy number.
Case #4: 4 is an Unhappy number.
Case #5: 5 is an Unhappy number.
Case #6: 6 is an Unhappy number.
Case #7: 7 is a Happy number.
Case #8: 8 is an Unhappy number.
Case #9: 9 is an Unhappy number.
Case #10: 10 is a Happy number.
Case #11: 11 is an Unhappy number.
Case #12: 12 is an Unhappy number.
Case #13: 13 is a Happy number.
Case #14: 14 is an Unhappy number.
Case #15: 15 is an Unhappy number.
Case #16: 16 is an Unhappy number.
Case #17: 17 is an Unhappy number.
Case #18: 18 is an Unhappy number.
Case #19: 19 is a Happy number.
Case #20: 20 is an Unhappy number.
Case #21: 111 is an Unhappy number.
Case #22: 1111 is an Unhappy number.
Case #23: 11111 is an Unhappy number.
Case #24: 1000 is a Happy number.
Case #25: 100 is a Happy number.
Case #26: 10 is a Happy number.
Case #27: 101 is an Unhappy number.
Case #28: 1111111 is a Happy number.
Case #29: 10111111 is a Happy number.
Case #30: 11110111 is a Happy number.
Case #31: 22 is an Unhappy number.
Case #32: 55 is an Unhappy number.
Case #33: 99 is an Unhappy number.
Case #34: 109 is a Happy number.
Case #35: 10900 is a Happy number.
Case #36: 91 is a Happy number.
Case #37: 900001 is a Happy number.
#include<stdio.h>
int main(void)
{
unsigned long a,b,i,c,num[500],u[500],sum;
scanf("%lu",&c);
for(i=0;i<c;i++) scanf("%ld",&num[i]);
for(i=0;i<c;i++) u[i]=num[i];
for(i=0;i<c;i++) {
do{
sum=0;
a=u[i];
do{
b=a%10; //
sum=sum+(b*b);
a=a/10;
} while(a!=0);
u[i]=sum;
}while(u[i] / 10 != 0);
if(sum==1) printf("Case #%lu: %lu is a Happy number.\n",i+1,num[i]);
else printf("Case #%lu: %lu is a Unhappy number.\n",i+1,num[i]);
}
return 0;
}
I guess that you submitted this as a C program. The Judge's compiler doesn't like C++ style comments while compiling C programs. Try to remove the redundant // from your code.
Also remember that you can't allocate on the stack big arrays. To avoid compile error for this reason make your arrays global. Maybe this doesn't apply for your program, I don't remember exctly what is the size of memory available on the stack.
Anyway you can check your mailbox as the judge sends an email with the errors from the compiler. If you didn't get it, check that the email address you gave when you registered to the online judge is correct and still valid.
}while(num / 10 != 0);
if(sum==1) printf("Case #%lu: %lu is a Happy number.\n",i+1,u);
else printf("Case #%lu: %lu is a Unhappy number.\n",i+1,u);
}
return 0;
}
Please post to the appropriate forum and possibly find a thread already open on this problem number.
As for your problem, you assume that you'll get at most 1000 numbers in input. probably this is not the case for Judge's data.
If you fix this ( you don't need to store all the numbers in input first and process it later, just process every number as you read it) you'll get a WA. Check the exact spelling for your answers.
Case #1: 1 is a Happy number.
Case #2: 2 is an Unhappy number.
Case #3: 3 is an Unhappy number.
Case #4: 4 is an Unhappy number.
Case #5: 5 is an Unhappy number.
Case #6: 6 is an Unhappy number.
Case #7: 7 is a Happy number.
Case #8: 8 is an Unhappy number.
Case #9: 9 is an Unhappy number.
Case #10: 10 is a Happy number.
Case #11: 11 is an Unhappy number.
Case #12: 12 is an Unhappy number.
Case #13: 13 is a Happy number.
Case #14: 14 is an Unhappy number.
Case #15: 15 is an Unhappy number.
Case #16: 16 is an Unhappy number.
Case #17: 17 is an Unhappy number.
Case #18: 18 is an Unhappy number.
Case #19: 19 is a Happy number.
Case #20: 20 is an Unhappy number.
Case #21: 111 is an Unhappy number.
Case #22: 1111 is an Unhappy number.
Case #23: 11111 is an Unhappy number.
Case #24: 1000 is a Happy number.
Case #25: 100 is a Happy number.
Case #26: 10 is a Happy number.
Case #27: 101 is an Unhappy number.
Case #28: 1111111 is a Happy number.
Case #29: 10111111 is a Happy number.
Case #30: 11110111 is a Happy number.
Case #31: 22 is an Unhappy number.
Case #32: 55 is an Unhappy number.
Case #33: 99 is an Unhappy number.
Case #34: 109 is a Happy number.
Case #35: 10900 is a Happy number.
Case #36: 91 is a Happy number.
Case #37: 900001 is a Happy number.
Raiyan Kamal's sample inputs is correct for my program.
I submit it but got WA.
Could anyone help me.