10070 - Leap Year or Not Leap Year and ...

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

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: UVA 10070

Post by brianfry713 » Wed Jun 11, 2014 11:04 pm

brianfry713 wrote:The year can be bigger than a long long can handle, my AC code assumes a line can be up to 1000000 digits long.
Check input and AC output for thousands of problems on uDebug!

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

10070- Leap year or not Leap year

Post by Shahidul.CSE » Wed Jul 16, 2014 1:14 pm

Why having WA with my code?

I am getting correct output of given simple input.
And also getting correct output as:
for 2100 huluculu,
for 22055 ordinary,
for 16555 ordinary .

I checked for int type also.
Where is the wrong?

Code: Select all

#include<stdio.h>
int main()
{
    freopen("10070.txt", "r", stdin);
    long long int lp,h,b,yr;
    while(scanf("%lld",&yr)!=EOF)
    {
        lp=h=b=0;
        if((yr%4==0 && yr%100!=0) || yr%400==0)
            lp=1;
        if(yr%15==0)
            h=1;
        if(lp==1 && yr%55==0)
            b=1;
        if(lp==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(lp==0 && h==0 && b==0)
            printf("This is an ordinary year.\n");

        printf("\n");


    }
    return 0;
}
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 1070- Leap year or not Leap year

Post by lighted » Wed Jul 16, 2014 2:07 pm

If there is a thread about your problem, please use it.
Don't open new thread. First of all use search by problem number (10070 for this problem)
http://acm.uva.es/board/search.php?keyw ... b3decb6507

For this problem there are many existing threads. One of them is below
http://acm.uva.es/board/viewtopic.php?f ... 07#p369473

The main reason why you get WA is the post written there
brianfry713 wrote:The year can be bigger than a long long can handle, my AC code assumes a line can be up to 1000000 digits long.
If you have problems read that posts. :wink:

By the way problems number is 10070 not 1070.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Shahidul.CSE
Experienced poster
Posts: 148
Joined: Sun Jul 13, 2014 4:32 am
Location: Rangpur, Bangladesh

Re: 1070- Leap year or not Leap year

Post by Shahidul.CSE » Wed Jul 16, 2014 2:17 pm

Thank you !! :P
Md. Shahidul Islam
Dept. of CSE at Begum Rokeya University, Rangpur, Bangladesh
UVa id: http://uhunt.felix-halim.net/id/438420
My facebook account,
Email me: shahidul.cse.brur@gmail.com

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 1070- Leap year or not Leap year

Post by brianfry713 » Wed Jul 16, 2014 7:45 pm

Don't read from a file.
Check input and AC output for thousands of problems on uDebug!

tausiftt5238
New poster
Posts: 2
Joined: Thu Aug 14, 2014 2:25 pm

Re: 10070 - Leap Year or Not Leap Year and …

Post by tausiftt5238 » Thu Aug 14, 2014 2:27 pm

could anyone tell me why i'm getting WA ?
thank you in advance

Code: Select all

#include <stdio.h>
#include <string.h>
int div_4(char a[])
{
	int i,remainder = 0;
	for(i=0;a[i]!=0;i++)
	{
		remainder = (remainder*10 + a[i]-48)%4;
	}
	if(remainder == 0)
		return 1;
	else
		return 0;
}
int div_15(char a[])
{
	int i,remainder = 0;
	for(i=0;a[i]!=0;i++)
	{
		remainder = (remainder*10 + a[i]-48)%15;
	}
	if(remainder == 0)
		return 1;
	else
		return 0;
}
int div_55(char a[])
{
	int i,remainder = 0;
	for(i=0;a[i]!=0;i++)
	{
		remainder = (remainder*10 + a[i]-48)%55;
	}
	if(remainder == 0)
		return 1;
	else
		return 0;
}
int div_100(char a[])
{
	int i,remainder = 0;
	for(i=0;a[i]!=0;i++)
	{
		remainder = (remainder*10 + a[i]-48)%100;
	}
	if(remainder == 0)
		return 1;
	else
		return 0;
}
int div_400(char a[])
{
	int i,remainder = 0;
	for(i=0;a[i]!=0;i++)
	{
		remainder = (remainder*10 + a[i]-48)%400;
	}
	if(remainder == 0)
		return 1;
	else
		return 0;
}
int main()
{
	char a[1000000];
	int b4,b15,b55,b100,b400;
	int flag,leap;
	int start = 0;
	while(gets(a)!=NULL)
	{
		leap = flag = 0;
		if(start != 0)
			printf("\n");
		b4 = div_4(a);
		b15 = div_15(a);
		b55 = div_55(a);
		b100 = div_100(a);
		b400 = div_400(a);
		if((b4==1&&b100!=0)||(b400))
		{
			printf("This is leap year.\n");
			leap = 1;
			flag = 1;
		}
		if(b15)
		{
			printf("This is huluculu festival year.\n");
			flag = 1;
		}
		if(b55)
		{
			if(leap == 1)
				printf("This is bulukulu festival year.\n");
		}
		if(flag != 1)
			printf("This is an ordinary year.\n");
		start = 1;
	}
	return 0;
}

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10070 - Leap Year or Not Leap Year and …

Post by lighted » Thu Aug 14, 2014 4:27 pm

You must check input in this thread first. Your program gives wrong output. For example
osan wrote:please check this input & output. i hope these will help u.

INPUT
2200
3000
6000
2000
10500
5500
OUTPUT
This is an ordinary year.

This is huluculu festival year.

This is leap year.
This is huluculu festival year.

This is leap year.

This is huluculu festival year.

This is an ordinary year.
& one thing ur code is giving a extra blank line after last output. be careful about this.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

nasim.ruet
New poster
Posts: 10
Joined: Sat Sep 06, 2014 12:44 pm

Re: 10070 - Leap Year or Not Leap Year and ...

Post by nasim.ruet » Wed Sep 17, 2014 7:34 pm

please help me . i cannot find why wrong ans : :roll: :oops:


import java.math.BigInteger;
import java.util.Scanner;

public class Main {

private static Scanner scanner;

public static void main(String[] args) {
scanner = new Scanner(System.in);
BigInteger number;
boolean check;

while (scanner.hasNext()) {
number = scanner.nextBigInteger();

check=false;
if (number.mod(BigInteger.valueOf(4)).equals(BigInteger.ZERO)) {
if (number.mod(BigInteger.valueOf(100)).equals(BigInteger.ZERO)) {
if (number.mod(BigInteger.valueOf(400)).equals(BigInteger.ZERO)) {
System.out.println("This is leap year.");
check=true;
}
else {
check=false;
}
}
else {
System.out.println("This is leap year.");
check=true;
}
}
if (number.mod(BigInteger.valueOf(15)).equals(BigInteger.ZERO)) {
System.out.println("This is huluculu festival year.");
check=true;
}
if ( check==true && number.mod(BigInteger.valueOf(55)).equals(BigInteger.ZERO))
System.out.println("This is buluculu festival year.");
if(check==false )
System.out.println("This is an ordinary year.");
System.out.println();


}
}

}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10070 - Leap Year or Not Leap Year and ...

Post by brianfry713 » Wed Sep 17, 2014 8:12 pm

A blank line should separate the output for each line of input.
Don't print an extra blank line at the end.
Check input and AC output for thousands of problems on uDebug!

bgcsaif
New poster
Posts: 38
Joined: Mon Sep 29, 2014 4:03 pm

Re: 10070 - Leap Year or Not Leap Year and ...

Post by bgcsaif » Mon Oct 06, 2014 10:38 am

I tried modular arithmatic to handle big input. I tried many inputs and it is okay. . . . May be i have formatting problems in my code. Can you help me with it please?

Code: Select all

Thanks! Code removed after AC
Last edited by bgcsaif on Mon Oct 06, 2014 7:45 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10070 - Leap Year or Not Leap Year and ...

Post by lighted » Mon Oct 06, 2014 1:15 pm

Try to check input in this thread first. I left 3 cases which your code fails.
alu_mathics wrote:try with this
456464484515645448647512343674234567564234564784234564754742345647424500
838286831260478655
838286831260478655
Output:
This is huluculu festival year.

This is huluculu festival year.

This is huluculu festival year.
If you can pass this input , hope your code will get A.C.
Don't forget to remove your code after getting accepted. 8)
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

bgcsaif
New poster
Posts: 38
Joined: Mon Sep 29, 2014 4:03 pm

Re: 10070 - Leap Year or Not Leap Year and ...

Post by bgcsaif » Mon Oct 06, 2014 2:43 pm

:( I passed those input. But still WA.

Code: Select all

Thanks! Code removed after AC
Last edited by bgcsaif on Mon Oct 06, 2014 7:47 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10070 - Leap Year or Not Leap Year and ...

Post by lighted » Mon Oct 06, 2014 3:12 pm

A blank line should separate the output for each line of input
Don't print blank line after last case.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

gautamzero
New poster
Posts: 32
Joined: Fri Oct 10, 2014 1:10 pm
Location: Sylhet, Bangladesh

please help:(

Post by gautamzero » Fri Oct 10, 2014 1:40 pm

what is the problem in my code :(
got WA three times :(
is there any critical input...

Code: Select all

GOT AC
Last edited by gautamzero on Fri Oct 10, 2014 6:43 pm, edited 1 time in total.

lighted
Guru
Posts: 585
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 10070 - Leap Year or Not Leap Year and ...

Post by lighted » Fri Oct 10, 2014 3:15 pm

You are printing extra character after last case.
Change reading to

Code: Select all

#include <iostream>
..
int ok = 0;
char ch;
while(std::cin.getline(num, 10000))   // gets(num) also works
{
    ..
    if (ok++) puts("");
        
    if(a==1)
    ..
    else if(a==0&&c==0)
        printf("This is an ordinary year.\n");
}
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 100 (10000-10099)”