10070 - Leap Year or Not Leap Year and ...
Moderator: Board moderators
-
- Experienced poster
- Posts: 106
- Joined: Sun Feb 17, 2002 2:00 am
- Location: Seoul, South Korea
- Contact:
10070 - Leap Year or Not Leap Year and ...
It's so strange problem. Its code is so simple, and I programmed it
easy. But I got wrong answer. I declared three boolean variables,
( check leap year, hulucul, bulukulu ) and check each of year.
Here is my pseudocode
=====================================
[cpp]// leap means leap year,
// hulu means huluculu festival year
// baku means bulukulu festival year
if( year%4 == 0 )
{
if( year%100 == 0 )
if( year%400 == 0 ) leap = true;
else leap = false;
else leap = true;
}
if( year%15 == 0 ) hulu = true;
if( leap && year%55 == 0 ) bulu = true;
check each year type and print...[/cpp]=====================================
Which of my code ( or solution ) is wrong?
Please give me some hint .
Thanks you.
easy. But I got wrong answer. I declared three boolean variables,
( check leap year, hulucul, bulukulu ) and check each of year.
Here is my pseudocode
=====================================
[cpp]// leap means leap year,
// hulu means huluculu festival year
// baku means bulukulu festival year
if( year%4 == 0 )
{
if( year%100 == 0 )
if( year%400 == 0 ) leap = true;
else leap = false;
else leap = true;
}
if( year%15 == 0 ) hulu = true;
if( leap && year%55 == 0 ) bulu = true;
check each year type and print...[/cpp]=====================================
Which of my code ( or solution ) is wrong?
Please give me some hint .
Thanks you.
HI~
In the problem description it states that "All the years will not be less than 2000 (to avoid the earlier different rules for leap years). Please don
Another problem
Hi!
I have another problem connected with this task...
It is written :
4515
And the answer :
This is huluculu festival year.
But this is not the leap year so shouldn't be there: This is an ordinary year written ???
I have no idea...
Please tell me where my mistake is, because I have no idea![:-?](./images/smilies/icon_confused.gif)
I have another problem connected with this task...
It is written :
But in the sample input it isIf the year is not leap year print the line 'This is an ordinary year.'
4515
And the answer :
This is huluculu festival year.
But this is not the leap year so shouldn't be there: This is an ordinary year written ???
I have no idea...
Please tell me where my mistake is, because I have no idea
![:-?](./images/smilies/icon_confused.gif)
Help problem 10070
Can you tell me what is wrong with my problem code? I get "wrong answer".This is my code:
#include<stdio.h>
int main()
{
unsigned long year;
int c;
while(scanf("%ld",&year)==1)
{
if(year>=2000)
{
c=0;
if(year%4==0 || year%400==0 || year%55==0)
{
printf("This is leap year");
c++;
}
if(year%15==0)
{
if(c==1)
printf("\nThis is huluculu festival year");
else
printf("This is huluculu festival year");
c++;
}
if(year%55==0)
{
if(c>0)
printf("\nThis is buluculu festival year");
else
printf("This is buluculu festival year");
c++;
}
if(c==0)
printf("This is an ordinary year");
printf("\n\n");
}
}
return 0;
}
#include<stdio.h>
int main()
{
unsigned long year;
int c;
while(scanf("%ld",&year)==1)
{
if(year>=2000)
{
c=0;
if(year%4==0 || year%400==0 || year%55==0)
{
printf("This is leap year");
c++;
}
if(year%15==0)
{
if(c==1)
printf("\nThis is huluculu festival year");
else
printf("This is huluculu festival year");
c++;
}
if(year%55==0)
{
if(c>0)
printf("\nThis is buluculu festival year");
else
printf("This is buluculu festival year");
c++;
}
if(c==0)
printf("This is an ordinary year");
printf("\n\n");
}
}
return 0;
}
Help problem 10070
What can I do now?Can you give me any idea?
still cannot solve
Hmm... I tried implementing a large array and some number theory to check for divisibility... but this still doesnt work. perhaps someone could help me spot my mistake please? thanks a lot!
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
#include <stdio.h>
void main()
{
long long y;
char yr[5000002];
int x=0,l;
while (gets(yr))
{
char yy[100];
long z=strlen(yr);
long i;
int ok=0;
if (strlen(yr)>5)
{
sprintf (yy,"%c%c%c%c%c", yr[z-5], yr[z-4], yr[z-3], yr[z-2], yr[z-1]);
}
else
strcpy(yy,yr);
y=atol(yy);
l=0;
if ((y%4==0 && y%100!=0) || (y%400==0))
{
ok=1;
cout << "This is leap year.\n";
l=1;
}
if (y%5==0)
{
y=0;
for (i=0;i<z;i++)
{
y=(y+yr)%3;
}
if (y%3==0)
{
ok=1;
cout << "This is huluculu festival year.\n";
}
y=0;
for (i=0;i<z;i++)
{
if (i%2)
y=(y+yr)%11;
else
y=(y-yr)%11;
}
if (l && (y%11==0))
{
ok=1;
cout << "This is bulukulu festival year.\n";
}
}
if (!ok)
cout << "This is an ordinary year.\n";
cout << endl;
}
}
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
#include <stdio.h>
void main()
{
long long y;
char yr[5000002];
int x=0,l;
while (gets(yr))
{
char yy[100];
long z=strlen(yr);
long i;
int ok=0;
if (strlen(yr)>5)
{
sprintf (yy,"%c%c%c%c%c", yr[z-5], yr[z-4], yr[z-3], yr[z-2], yr[z-1]);
}
else
strcpy(yy,yr);
y=atol(yy);
l=0;
if ((y%4==0 && y%100!=0) || (y%400==0))
{
ok=1;
cout << "This is leap year.\n";
l=1;
}
if (y%5==0)
{
y=0;
for (i=0;i<z;i++)
{
y=(y+yr)%3;
}
if (y%3==0)
{
ok=1;
cout << "This is huluculu festival year.\n";
}
y=0;
for (i=0;i<z;i++)
{
if (i%2)
y=(y+yr)%11;
else
y=(y-yr)%11;
}
if (l && (y%11==0))
{
ok=1;
cout << "This is bulukulu festival year.\n";
}
}
if (!ok)
cout << "This is an ordinary year.\n";
cout << endl;
}
}
-
- New poster
- Posts: 1
- Joined: Tue Jul 30, 2002 7:31 pm
- Location: Bangladesh
10070 EASY BUT WA
#include<stdio.h>
#include<string.h>
#define MAX 5000
char year[MAX];
int leap,bul,hul;
void checkLeap()
{
long len,i,count;
long tot=0;
len=strlen(year);
if((year[len-1]=='0')&&(year[len-2]=='0'))
{
i=len-2;
for(count=len-4;count<i;count++)
if(count>=0)
tot=tot*10+(year[count]-'0');
if(!(tot%4))
{
leap=1;
return;
}
}
else
{
if((len-2)>=0)
tot=(year[len-2]-'0');
if((len-1)>=0)
tot=tot*10+(year[len-1]-'0');
if(!(tot%4))
{
leap=1;
return;
}
}
}
void checkHul()
{
long i;
long len;
long tot=0;
len=strlen(year);
if((year[len-1]=='5')||(year[len-1]=='0'))
{
for(i=0;i<len;i++)
tot+=(year-'0');
if(!(tot%3))
hul=1;
}
return;
}
void checkBul()
{
long i,len;
len=strlen(year);
long odd=0,even=0,chk;
if(leap)
{
if((year[len-1]=='0')||(year[len-1]=='5'))
{
for(i=0;i<len-2;i+=2)
{
odd+=(year-'0');
even+=(year[i+1]-'0');
}
chk=odd-even;
if(chk<0)
chk=-chk;
if(!(chk%11))
bul=1;
}
}
return;
}
void main()
{
int testCase=0;
for(;;)
{
if(1!=scanf("%s",year))
break;
if(testCase)
printf("\n");
leap=hul=bul=0;
checkLeap();
checkHul();
checkBul();
if(leap)
printf("This is leap year.\n");
if(hul)
printf("This is huluculu festival year.\n");
if(bul)
printf("This is bulukulu festival year.\n");
if(!leap&&!hul&&!bul)
printf("This is an ordinary year.\n");
testCase++;
}
}
#include<string.h>
#define MAX 5000
char year[MAX];
int leap,bul,hul;
void checkLeap()
{
long len,i,count;
long tot=0;
len=strlen(year);
if((year[len-1]=='0')&&(year[len-2]=='0'))
{
i=len-2;
for(count=len-4;count<i;count++)
if(count>=0)
tot=tot*10+(year[count]-'0');
if(!(tot%4))
{
leap=1;
return;
}
}
else
{
if((len-2)>=0)
tot=(year[len-2]-'0');
if((len-1)>=0)
tot=tot*10+(year[len-1]-'0');
if(!(tot%4))
{
leap=1;
return;
}
}
}
void checkHul()
{
long i;
long len;
long tot=0;
len=strlen(year);
if((year[len-1]=='5')||(year[len-1]=='0'))
{
for(i=0;i<len;i++)
tot+=(year-'0');
if(!(tot%3))
hul=1;
}
return;
}
void checkBul()
{
long i,len;
len=strlen(year);
long odd=0,even=0,chk;
if(leap)
{
if((year[len-1]=='0')||(year[len-1]=='5'))
{
for(i=0;i<len-2;i+=2)
{
odd+=(year-'0');
even+=(year[i+1]-'0');
}
chk=odd-even;
if(chk<0)
chk=-chk;
if(!(chk%11))
bul=1;
}
}
return;
}
void main()
{
int testCase=0;
for(;;)
{
if(1!=scanf("%s",year))
break;
if(testCase)
printf("\n");
leap=hul=bul=0;
checkLeap();
checkHul();
checkBul();
if(leap)
printf("This is leap year.\n");
if(hul)
printf("This is huluculu festival year.\n");
if(bul)
printf("This is bulukulu festival year.\n");
if(!leap&&!hul&&!bul)
printf("This is an ordinary year.\n");
testCase++;
}
}
I can't mark my mistake..........can anyone help me??
long is not enough
you should use string to read the year
me w/a too,help!!!
#include "iostream.h"
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
struct str
{
char base[100000];
int len;
};
bool mod3(str year)
{
long sum;
div_t t;
sum=0;
int i;
for(i=0;i<year.len;i++)
sum+=(year.base-'0');
t=div(sum,3);
if(t.rem==0)
return true;
return false;
}
bool mod4(str year)
{
div_t t;
t=div((year.base[year.len-2]-'0'),2);
if(t.rem==0)
{
if(((year.base[year.len-1]-'0')==0)
||((year.base[year.len-1]-'0')==4)
||((year.base[year.len-1]-'0')==8))
return true;
}
else
if(((year.base[year.len-1]-'0')==2)
||((year.base[year.len-1]-'0')==6))
return true;
return false;
}
bool mod5(str year)
{
if((year.base[year.len-1]=='0')||(year.base[year.len-1]=='5'))
return true;
return false;
}
bool mod11(str year)
{
int i;
i=0;
long sum1,sum2;
sum1=0;
sum2=0;
while(i<year.len)
{
sum1+=(year.base-'0');
i+=2;
}
i=1;
while(i<year.len)
{
sum2+=(year.base-'0');
i+=2;
}
if(sum1==sum2)
return true;
return false;
}
bool mod100(str year)
{
if(((year.base[year.len-2]-'0')==0)&&((year.base[year.len-1]-'0')==0))
return true;
return false;
}
bool mod400(str year)
{
div_t t;
t=div((year.base[year.len-4]-'0'),2);
if(((year.base[year.len-2]-'0')==0)&&((year.base[year.len-1]-'0')==0))
{
if(t.rem==0)
{
if(((year.base[year.len-3]-'0')==0)
||((year.base[year.len-3]-'0')==4)
||((year.base[year.len-3]-'0')==8))
return true;
}
else
if(((year.base[year.len-3]-'0')==2)
||((year.base[year.len-3]-'0')==6))
return true;
}
return false;
}
bool isleap(str year)
{
bool f1,f2,f3;
f1=mod4(year);
f2=mod100(year);
f3=mod400(year);
if((f1&&(!f2))||f3)
return true;
else
return false;
}
bool ishf(str year)
{
if(mod3(year)&&mod5(year))
return true;
else
return false;
}
bool isbf(str year)
{
if(mod11(year)&&mod5(year)&&isleap(year))
return true;
else
return false;
}
void main()
{
str year;
bool f;
while(!feof(stdin))
{
f=false;
gets(year.base);
year.len=strlen(year.base);
if(isleap(year))
{
puts("This is leap year.");
f=true;
}
if(ishf(year))
{
puts("This is huluculu festival year.");
f=true;
}
if(isbf(year))
{
puts("This is bulukulu festival year.");
f=true;
}
if(!f)
puts("This is an ordinary year.");
puts("");
}
}
#include "stdlib.h"
#include "string.h"
#include "stdio.h"
struct str
{
char base[100000];
int len;
};
bool mod3(str year)
{
long sum;
div_t t;
sum=0;
int i;
for(i=0;i<year.len;i++)
sum+=(year.base-'0');
t=div(sum,3);
if(t.rem==0)
return true;
return false;
}
bool mod4(str year)
{
div_t t;
t=div((year.base[year.len-2]-'0'),2);
if(t.rem==0)
{
if(((year.base[year.len-1]-'0')==0)
||((year.base[year.len-1]-'0')==4)
||((year.base[year.len-1]-'0')==8))
return true;
}
else
if(((year.base[year.len-1]-'0')==2)
||((year.base[year.len-1]-'0')==6))
return true;
return false;
}
bool mod5(str year)
{
if((year.base[year.len-1]=='0')||(year.base[year.len-1]=='5'))
return true;
return false;
}
bool mod11(str year)
{
int i;
i=0;
long sum1,sum2;
sum1=0;
sum2=0;
while(i<year.len)
{
sum1+=(year.base-'0');
i+=2;
}
i=1;
while(i<year.len)
{
sum2+=(year.base-'0');
i+=2;
}
if(sum1==sum2)
return true;
return false;
}
bool mod100(str year)
{
if(((year.base[year.len-2]-'0')==0)&&((year.base[year.len-1]-'0')==0))
return true;
return false;
}
bool mod400(str year)
{
div_t t;
t=div((year.base[year.len-4]-'0'),2);
if(((year.base[year.len-2]-'0')==0)&&((year.base[year.len-1]-'0')==0))
{
if(t.rem==0)
{
if(((year.base[year.len-3]-'0')==0)
||((year.base[year.len-3]-'0')==4)
||((year.base[year.len-3]-'0')==8))
return true;
}
else
if(((year.base[year.len-3]-'0')==2)
||((year.base[year.len-3]-'0')==6))
return true;
}
return false;
}
bool isleap(str year)
{
bool f1,f2,f3;
f1=mod4(year);
f2=mod100(year);
f3=mod400(year);
if((f1&&(!f2))||f3)
return true;
else
return false;
}
bool ishf(str year)
{
if(mod3(year)&&mod5(year))
return true;
else
return false;
}
bool isbf(str year)
{
if(mod11(year)&&mod5(year)&&isleap(year))
return true;
else
return false;
}
void main()
{
str year;
bool f;
while(!feof(stdin))
{
f=false;
gets(year.base);
year.len=strlen(year.base);
if(isleap(year))
{
puts("This is leap year.");
f=true;
}
if(ishf(year))
{
puts("This is huluculu festival year.");
f=true;
}
if(isbf(year))
{
puts("This is bulukulu festival year.");
f=true;
}
if(!f)
puts("This is an ordinary year.");
puts("");
}
}
Solution for 10070
I have learnt another (perhaps easier) way of calculating the modulus of long integers. Thanks to Jiawei for letting me see his source code. Here is my accepted solution.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
char a[10000000];
void main(void){
int i,leap,ord,f=1;
while (cin >> a){
if (f)
f=0;
else
cout << endl;
int mod4,mod100,mod400,mod15,mod55;
mod4=mod100=mod400=mod15=mod55=0;
ord=1;leap=0;
for (i=0;i<strlen(a);i++)
{
mod4=(mod4*10+a-'0')%4;
mod100=(mod100*10+a-'0')%100;
mod400=(mod400*10+a-'0')%400;
mod15=(mod15*10+a-'0')%15;
mod55=(mod55*10+a-'0')%55;
}
if ((!mod4 && mod100) || !mod400)
{
leap=1;
ord=0;
cout << "This is leap year.\n";
}
if (!mod15)
{
ord=0;
cout << "This is huluculu festival year.\n";
}
if (leap && !mod55)
{
ord=0;
cout << "This is bulukulu festival year.\n";
}
if (ord)
cout << "This is an ordinary year.\n";
}
}
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream.h>
char a[10000000];
void main(void){
int i,leap,ord,f=1;
while (cin >> a){
if (f)
f=0;
else
cout << endl;
int mod4,mod100,mod400,mod15,mod55;
mod4=mod100=mod400=mod15=mod55=0;
ord=1;leap=0;
for (i=0;i<strlen(a);i++)
{
mod4=(mod4*10+a-'0')%4;
mod100=(mod100*10+a-'0')%100;
mod400=(mod400*10+a-'0')%400;
mod15=(mod15*10+a-'0')%15;
mod55=(mod55*10+a-'0')%55;
}
if ((!mod4 && mod100) || !mod400)
{
leap=1;
ord=0;
cout << "This is leap year.\n";
}
if (!mod15)
{
ord=0;
cout << "This is huluculu festival year.\n";
}
if (leap && !mod55)
{
ord=0;
cout << "This is bulukulu festival year.\n";
}
if (ord)
cout << "This is an ordinary year.\n";
}
}
-
- New poster
- Posts: 5
- Joined: Thu Aug 22, 2002 9:41 am
- Location: Taiwan
- Contact:
10070 Output Limit Exceeded
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];
int len,i,m400,m15,m55,l,h,b,f=1,pass=1;
do{
gets(s);
len=strlen(s);
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;
else
pass=0;
if(pass==0)
break;
m400=(y[2]*100+y[1]*10+y[0])%400;
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;
if(f==0)
printf("\n");
f=0;
l=h=b=0;
if((m400%4==0&&m400%100!=0)||m400==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");
}while(1);
}[/c]
[c]#include <stdio.h>
#include <string.h>
main()
{
char s[10000];
int y[10000];
int len,i,m400,m15,m55,l,h,b,f=1,pass=1;
do{
gets(s);
len=strlen(s);
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;
else
pass=0;
if(pass==0)
break;
m400=(y[2]*100+y[1]*10+y[0])%400;
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;
if(f==0)
printf("\n");
f=0;
l=h=b=0;
if((m400%4==0&&m400%100!=0)||m400==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");
}while(1);
}[/c]
Re: me w/a too,help!!!
chaojinn wrote:#include "iostream.h"
bool mod11(str year)
{
int i;
i=0;
long sum1,sum2;
sum1=0;
sum2=0;
while(i<year.len)
{
sum1+=(year.base-'0');
i+=2;
}
i=1;
while(i<year.len)
{
sum2+=(year.base-'0');
i+=2;
}
if(sum1==sum2)
return true;
return false;
}
it should be
Code: Select all
((sum1-sum2)%11 == 0)