Maybe 10000 elements are not enough?Meng-Hsuan Wu wrote:This is my source code for problem 10070. When I ran it on my computer, it worked well when I input a long number. But I got "Output Limit Exceeded" when I submit it. Can anyone help me?
[c]#include <stdio.h>
#include <string.h>
main()
{
char s[10000];
int y[10000];
//...
[/c]
10070 - Leap Year or Not Leap Year and ...
Moderator: Board moderators
Re: 10070 Output Limit Exceeded
10070 Leap year or not... what could be wrong
![:roll:](./images/smilies/icon_rolleyes.gif)
i realize that i have to use strings to take input and i have used a technique to find the divisibility of large numbers by smaller ones. yet i get WA. Could someone help me to spot the mistake.
Cut
![:D](./images/smilies/icon_biggrin.gif)
![:P](./images/smilies/icon_razz.gif)
![:)](./images/smilies/icon_smile.gif)
![:lol:](./images/smilies/icon_lol.gif)
Last edited by shamim on Mon Apr 28, 2003 8:26 am, edited 1 time in total.
Re: 10070 Leap year or not... what could be wrong
[c]
if (leap)
{
printf ("This is leap year.\n");
if (isdiv (line, 11)) bulu = 1;
}
[/c]![:wink:](./images/smilies/icon_wink.gif)
if (leap)
{
printf ("This is leap year.\n");
if (isdiv (line, 11)) bulu = 1;
}
[/c]
I supose this is your problemBulukulu festival (Happens on years divisible by 55 provided that is also a leap year)
![:wink:](./images/smilies/icon_wink.gif)
-
- New poster
- Posts: 30
- Joined: Sat Nov 30, 2002 1:04 pm
-
- Learning poster
- Posts: 93
- Joined: Sun Jan 12, 2003 3:30 pm
10070 - Leap Year or Not Leap Year and ...
I need some suggestion here ...
Do I have to use very long number in this case ???
Can I just use int or long ???
please help!
Do I have to use very long number in this case ???
Can I just use int or long ???
please help!
-
- System administrator & Problemsetter
- Posts: 399
- Joined: Sat Jan 12, 2002 2:00 am
Yes
Yes numbers are out of range of any conventional data types - integer, long, int64 or long long etc
-
- Experienced poster
- Posts: 187
- Joined: Wed Dec 11, 2002 2:03 pm
- Location: Mount Papandayan, Garut
-
- Learning poster
- Posts: 93
- Joined: Sun Jan 12, 2003 3:30 pm
10070
what's wromg with my program
? would anyone tell me what's my wrong? this is my code :
[c]
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main()
{
char s[10000];
int y[10000];
int len,i,m4,m15,m55,l,h,b,a,cek;
while(scanf("%s",s)==1)
{
fflush(stdin);
len=strlen(s);
for(i=0;i<len;i++)
{
if(!isdigit(s)) exit(1);
}
if(len<3) continue;
if(len==4)
{
cek=0;
for(i=0;i<4;i++)
{
cek=cek*10+s-'0';
}
if(cek<2000) continue;
}
if(len==0||s[0]<48||s[0]>57)
break;
for(i=9999;i>=len;i--)
y=0;
for(i=len-1;i>=0;i--)
if(s[len-1-i]>=48&&s[len-1-i]<=57)
y=s[len-1-i]-48;
m4=(y[1]*10+y[0])%4;
m15=y[len-1];
for(i=len-2;i>=0;i--)
m15=(m15*10+y)%15;
m55=y[len-1];
for(i=len-2;i>=0;i--)
m55=(m55*10+y)%55;
l=h=b=0;
if(m4==0)
l=1;
if(m15==0)
h=1;
if(l==1&&m55==0)
b=1;
if(l==1)
printf("This is leap year.\n");
if(h==1)
printf("This is huluculu festival year.\n");
if(b==1)
printf("This is bulukulu festival year.\n");
if(l+h+b==0)
printf("This is an ordinary year.\n");
printf("\n");
}
return 0;
}[/c]
thank you
best regards,
awik
![:cry:](./images/smilies/icon_cry.gif)
[c]
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
int main()
{
char s[10000];
int y[10000];
int len,i,m4,m15,m55,l,h,b,a,cek;
while(scanf("%s",s)==1)
{
fflush(stdin);
len=strlen(s);
for(i=0;i<len;i++)
{
if(!isdigit(s)) exit(1);
}
if(len<3) continue;
if(len==4)
{
cek=0;
for(i=0;i<4;i++)
{
cek=cek*10+s-'0';
}
if(cek<2000) continue;
}
if(len==0||s[0]<48||s[0]>57)
break;
for(i=9999;i>=len;i--)
y=0;
for(i=len-1;i>=0;i--)
if(s[len-1-i]>=48&&s[len-1-i]<=57)
y=s[len-1-i]-48;
m4=(y[1]*10+y[0])%4;
m15=y[len-1];
for(i=len-2;i>=0;i--)
m15=(m15*10+y)%15;
m55=y[len-1];
for(i=len-2;i>=0;i--)
m55=(m55*10+y)%55;
l=h=b=0;
if(m4==0)
l=1;
if(m15==0)
h=1;
if(l==1&&m55==0)
b=1;
if(l==1)
printf("This is leap year.\n");
if(h==1)
printf("This is huluculu festival year.\n");
if(b==1)
printf("This is bulukulu festival year.\n");
if(l+h+b==0)
printf("This is an ordinary year.\n");
printf("\n");
}
return 0;
}[/c]
thank you
best regards,
awik
[quote="10153EN"]I solved this problem by storing the year number (which can be very large) in an integer array. Then check this year with some number theory.
For example, if a numbe if divible by 3, then the sum of all of it's digits is ....[/quote]
Excellent idea!!
What's the rule for knowing if a number is divisible by 11?
For example, if a numbe if divible by 3, then the sum of all of it's digits is ....[/quote]
Excellent idea!!
What's the rule for knowing if a number is divisible by 11?