10591-RunTimeError

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

Moderator: Board moderators

10591-RunTimeError

Postby 59557RC » Thu Apr 07, 2005 10:44 pm

i don't understand what's wrong. it ran without any problem & the output is also correct.so why RuntimeError


#include<stdio.h>

int main(void)
{


unsigned long a,b,i,c,num[1000],u,sum=0;

scanf("%lu",&c);
for(i=0;i<c;i++) scanf("%ld",&num[i]);

for(i=0;i<c;i++) {
u=num[i];
do{
sum=0;
a=num[i];



b=a%10;
sum=sum+(b*b);
a=a/10;
while(a!=0){

b=a%10;
sum=sum+(b*b);
a=a/10;

}



num[i]=sum;

}while(num[i] / 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;
}
aaa
59557RC
New poster
 
Posts: 26
Joined: Sun Mar 20, 2005 9:28 pm
Location: bangladesh

Re: 10591-RunTimeError

Postby CDiMa » Fri Apr 08, 2005 9:53 am

59557RC wrote:i don't understand what's wrong. it ran without any problem & the output is also correct.so why RuntimeError


#include<stdio.h>

int main(void)
{


unsigned long a,b,i,c,num[1000],u,sum=0;

scanf("%lu",&c);
for(i=0;i<c;i++) scanf("%ld",&num[i]);

for(i=0;i<c;i++) {
u=num[i];
do{
sum=0;
a=num[i];



b=a%10;
sum=sum+(b*b);
a=a/10;
while(a!=0){

b=a%10;
sum=sum+(b*b);
a=a/10;

}



num[i]=sum;

}while(num[i] / 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.

Ciao!!!

Claudio
CDiMa
Experienced poster
 
Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

Postby sn23581 » Fri Mar 18, 2011 6:46 am

a number is happy if it ends in 1 after any step of generating the square sum of the digits.
and a number is unhappy if it ends in 4 after any step of generating the square sum of the digits.

this optimisation gets AC :D
sn23581
New poster
 
Posts: 2
Joined: Thu Jul 29, 2010 2:02 pm


Return to Volume CV

Who is online

Users browsing this forum: No registered users and 1 guest