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

aaa111
New poster
Posts: 14
Joined: Sat Nov 21, 2009 2:55 pm

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

Post by aaa111 » Sun Jun 06, 2010 3:28 pm

Why am i getting wrong answer, i checked all output,they seems right to me:

Code: Select all

#include<stdio.h>
#include<string.h>

int div_by_100(char *year)
{
long int i;

i=strlen(year);
if((year[i-1]=='0')&&(year[i-2]=='0'))
    return 1;
return 0;
}

int div_by_4(char *year)
{
long int sum,i;

i=strlen(year);
sum=10*(year[i-2]-'0')+(year[i-1]-'0');
if(sum%4==0)
    return 1;
return 0;
}

int div_by_400(char *year)
{
long int sum1,i;

i=strlen(year);
sum1=1000*(year[i-4]-'0')+100*(year[i-3]-'0')+10*(year[i-2]-'0')+(year[i-1]-'0');
if(sum1%400==0)
    return 1;
return 0;
}

int div_by_5(char *year)
{
long int i;

i=strlen(year);
if((year[i-1]=='0')||(year[i-1]=='5'))
    return 1;
return 0;
}

int  div_by_3(char *year)
{
long int i,len;
long sum;

len=strlen(year);
sum=0;
for(i=0;i<len;i++)
    {
    sum+=(year[i]-'0');
    }
if((sum%3)==0)
    return 1;
return 0;
}

int div_by_15(char *year)
{
if((div_by_5(year))&&(div_by_3(year)))
    return 1;
return 0;
}

int div_by_11(char *year)
{
long int i,len;
long sum;

len=strlen(year);
sum=0;

for(i=0;i<len;i++)
    {
    if(((i+1)%2)==0)
	sum-=(year[i]-'0');
    else
	sum+=(year[i]-'0');
    }

if((sum%11)==0)
    return 1;
return 0;
}

int div_by_55(char *year)
{
if(div_by_11(year))
    return 1;
return 0;
}

int main()
{
char year[100001];

int none=1;
int leap_year=0;
int flag=0;

while(gets(year))
    {
    if(((div_by_4(year))&&(div_by_100(year)==0))||(div_by_400(year)))
	{
	none=0;
	leap_year=1;
	printf("This is leap year.\n");
	}
    if((div_by_15(year)))
	{
	none=0;
	printf("This is huluculu festival year.\n");
	}
    if(leap_year==1)
	{
	if(div_by_55(year))
	   printf("This is bulukulu festival year.\n");
	}
    if(none)
	printf("This is an ordinary year.\n");
    if(flag==0)
      flag=1;
    else
      printf("\n");      
    none=1;
    leap_year=0;
    }
return 0;
}

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

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

Post by sazzadcsedu » Thu Jun 10, 2010 10:32 pm

To:>aaa111

Check this:
234234444444
your output:

This is leap year.
This is bulukulu festival year.

My Acc output:

This is leap year.
No way to be bulukulu festival year because not divisible by 55.


To:> iceb3rg

check this:
67665777776000000000000000000000000
6666666666666000600600000000066

your program output:

This is leap year.

This is leap year.

But My Acc output:

This is leap year.

This is an ordinary year.


But if u only test this input 6666666666666000600600000000066. then it outputs correctly.This means you have flaging problem.reinitialize everything before next input.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

yeasin_acm_solver
New poster
Posts: 11
Joined: Wed Jun 09, 2010 2:30 pm
Location: University Of Science & Technology Chittagong (USTC) Bangladesh

10070 - Why only huluculu

Post by yeasin_acm_solver » Sun Aug 22, 2010 10:27 am

/*************************************************************/
Muhammad Yeasin
University of Science & Technology Chittagong (USTC)
CSE- 11th Batch
Bangladesh
E-mail: gigabyte_yeasin@yahoo.com
/*************************************************************/

Accepted.

@ sazzadcsedu : Many Many Thanks To You..
Last edited by yeasin_acm_solver on Mon Aug 23, 2010 8:13 pm, edited 1 time in total.

yeasin_acm_solver
New poster
Posts: 11
Joined: Wed Jun 09, 2010 2:30 pm
Location: University Of Science & Technology Chittagong (USTC) Bangladesh

10070 Why wrong answer this code

Post by yeasin_acm_solver » Sun Aug 22, 2010 9:12 pm

/*************************************************************/
Muhammad Yeasin
University of Science & Technology Chittagong (USTC)
CSE- 11th Batch
Bangladesh
E-mail: gigabyte_yeasin@yahoo.com
/*************************************************************/

Accepted.

@ sazzadcsedu : Many Many Thanks To You..

sazzadcsedu
Experienced poster
Posts: 136
Joined: Sat Nov 29, 2008 8:01 am
Location: narayangong,bangladesh.
Contact:

Re: 10070 - Why only huluculu

Post by sazzadcsedu » Mon Aug 23, 2010 4:53 pm

Did you notice that in problem statement:-
the Bulukulu festival (Happens on years divisible by 55 provided that is also a leap year).
Read the problem statement carefully.And why you are creating new thread for every question ? there is a search box
in every volume.Insert your problem no. here and use the existing thread to ask your question.


Good luck.
Life is more complicated than algorithm.
http://felix-halim.net/uva/hunting.php?id=32359
For Hints: http://salimsazzad.wordpress.com

Eather
New poster
Posts: 28
Joined: Thu Jan 28, 2010 2:23 pm

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

Post by Eather » Fri Feb 25, 2011 9:17 am

I dont know why im getting WA.. plz help me...

Code: Select all

import java.util.*;
import java.math.*;
import java.io.*;

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)throws Exception {

        Scanner sc= new Scanner(System.in);
        
        BigInteger Year2;
        int ff=0;

        while(sc.hasNext()){
            if(ff==1)System.out.println();ff=1;
            int nt=0;

            Year2= sc.nextBigInteger();
            int l=0,h=0,b=0;

            if ( Year2.mod(BigInteger.valueOf(4)).compareTo(BigInteger.valueOf(0))==0)
                {
                    if ( Year2.mod(BigInteger.valueOf(100)).compareTo(BigInteger.valueOf(0))!=0)
                    {
                        l=1;nt=1;
                        if(Year2.mod(BigInteger.valueOf(55)).compareTo(BigInteger.ZERO)==0)
                        {
                             b=1;nt=1;
                        }
                    }
                    else if ( Year2.mod(BigInteger.valueOf(400)).compareTo(BigInteger.valueOf(0))==0)
                    {
                       l=1;nt=1;
                        if(Year2.mod(BigInteger.valueOf(55)).compareTo(BigInteger.ZERO)==0)
                        {
                            b=1;nt=1;
                        }
                    }
                }
             if(Year2.mod(BigInteger.valueOf(15)).compareTo(BigInteger.ZERO)==0)
            {
                h=1;nt=1;
            }

            if(l==1)System.out.println("This is Leap year.");
            if(h==1)System.out.println("This is huluculu festival year.");
            if(l==1 && b==1)System.out.println("This is bulukulu festival year.");


            if(nt==0)System.out.println("This is an ordinary year.");

            //System.out.println();
        }
    }
}

tanvir09
New poster
Posts: 1
Joined: Mon Mar 28, 2011 3:57 pm

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

Post by tanvir09 » Mon Mar 28, 2011 4:13 pm

I don't know why am i getting wrong answer, i checked all output,they seems right to me :x
plz help someone:

Code: Select all

#include<stdio.h>
#include<string.h>
char year[10001];
int main()
{
    int i,md4,md15,md55,l,md100,md400;
    int lip=0,hul=0,bul=0;
    while(scanf("%[0-9]s",year))
    {
        l=strlen(year);
        md4=0;md15=0;md55=0;md100=0;
        for(i=0;i<l;i++)
        {
            md4=(md4*10+year[i]-'0')%4;
            md15=(md15*10+year[i]-'0')%15;
            md55=(md55*10+year[i]-'0')%55;
            md400=(md400*10+year[i]-'0')%400;
            md100=(md100*10+year[i]-'0')%100;
        }
        //if((year[l-1]=='0')&&(year[l-2]=='0'))md100=0;
        //else md100=1;

         if(((md4==0)&&(md100!=0))||(md400==0))
        {
            lip=1;
            if(md55==0)bul=1;
        }
        if(md15==0)hul=1;
        if(lip==1)printf("This is leap year\n");
        if(hul==1)printf("This is huluculu festival year.\n");
        if(bul==1)printf("This is bulukulu festival year.\n");
        if((lip==0)&&(hul==0)&&(bul==0))printf("This is an ordinary year.\n");
        printf("\n");
        lip=0;hul=0;bul=0;
        fflush(stdin);

    }
    return 0;
}

Mohayemin
New poster
Posts: 2
Joined: Thu Apr 28, 2011 6:07 pm

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

Post by Mohayemin » Thu Apr 28, 2011 6:15 pm

Can someone find problem in my solution?
in my code d3, d4, d5, d11, d100, d400 are 1 if the input is divisible by the respective number.

Code: Select all

#include <stdio.h>
#include <string.h>

int L, i;
char Y[100000000];
int d3, d4, d5, d11, d100, d400;

void div3();
void div4();
void div5();
void div11();
void div100();
void div400();

int main (){
	int leap, hulu, bulu;
	int start = 1;
	
	while (scanf("%s", Y)!=EOF){
		if (!start){
			puts("");
		}
		start = 0;
		
		L = strlen(Y);
		div3();
		div4();
		div5();
		div11();
		div100();
		div400();
		
		leap = (d4 && !d100) || d400;	
		hulu = d3 && d5;
		bulu = leap && d5 && d11;
		
		if (!leap && !hulu){
			puts("This is an ordinary year.");
		}else {
			if(leap){
				puts("This is leap year.");
			}
			if (hulu){
				puts("This is huluculu festival year.");
			}
			if (bulu){
				puts("This is buluculu festival year.");
			}
		}
	}
	
	return 0;
}

void div3(){
	int s=0;
	for (i = 0; i < L; i ++){
		s+=Y[i];
	}
	
	d3 = (s%3 == 0);
}

void div4(){
	int n = 0;
	n += (Y[L-1]);
	n += (10*Y[L-2]);
	
	d4 = (n>>2<<2 == n);
}

void div5(){
	d5 = (Y[L-1] == '0')||(Y[L-1] == '5');
}

void div11(){
	int s = 0;
	int addFlag = 1;
	
	for (i = 0; i < L; i++){
		s+= (addFlag*Y[i]);
		addFlag = 0-addFlag;
	}
	
	if (addFlag == -1){
		s-='0';
	}
	
	d11 = (s%11 == 0);
}

void div100(){
	d100 = (Y[L-1] == '0') && (Y[L-2] == '0');
}

void div400(){
	int n = 0;
	n += (Y[L-3]);
	n += (10*Y[L-4]);
	
	d400 = div100 && (n>>2<<2 == n);
}

nonamebd
New poster
Posts: 1
Joined: Tue May 31, 2011 8:51 pm

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

Post by nonamebd » Tue Jun 07, 2011 8:17 pm

why am i getting WA??? my code works for all the inputs i tried.......

Code: Select all

#include <stdio.h>
#include <string.h>
#include <math.h>
      
      


main()
{
      char num[100000];
      unsigned long long a,b,c,d,dig,statL,statH,statB,numarr[100000],sum3,sum11A,sum11B,statX,sum11;
      
      
      while(gets(num))
      {               
                      dig=strlen(num);
                      
                      statL=0,statH=0,statB=0,statX=0;
                      for(a=0;a<=dig-1;a++)
                      {
                                           numarr[a]=num[a]-48;
                      }
       
                      b=numarr[dig-1]+(10*numarr[dig-2])+(100*numarr[dig-3])+(1000*numarr[dig-4]);
                      
                      if((b%4==0) && (b%100!=0)||(b%400 == 0))statL=1; 
                      
                      if((num[dig-1]=='5')||(num[dig-1]=='0'))
                      {                                       
                                                              sum3=0,sum11A=sum11B=0,sum11=0;
                                                              for(a=0;a<=dig-1;a++)
                                                              {
                                                                     sum3+=numarr[a];
                                                              }
                                                              
                                                              if(sum3%3==0)statH=1;
                                                              
                                                                          
                                                              for(a=1;a<=dig-1;a+=2)
                                                              {
                                                                      sum11A+=numarr[a];
                                                              }   
                                                              
                                                              for(a=0;a<=dig-1;a+=2)
                                                              {
                                                                      sum11B+=numarr[a];
                                                              }  
                                                              
                                                              sum11=sum11A-sum11B;
                                                              if(sum11%11==0)statB=1;
                                                              
                      }
                                                                        
                      if(statL==1)printf("This is leap year.\n");                                                   
                      if(statH==1)printf("This is huluculu festival year.\n");
                      if((statL==1)&&(statB==1)){
                                                 statX=1;
                                                 printf("This is bulukulu festival year.\n");
                                                 }
                      
                      if((statL==0)&&(statX==0)&&(statH==0))printf("This is an ordinary year.\n");
                      
                      printf("\n");
                      
                      
       }
       
       return 0;
       
       }      
                                        

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

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

Post by plamplam » Mon Jun 27, 2011 8:36 pm

There is no blank line after the last output. :P :P
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

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

Post by plamplam » Tue Jun 28, 2011 5:03 am

@tanvir09 change this part of your code
if(bul==1)printf("This is bulukulu festival year.\n"); to
if(bul==1 && lip == 1)printf("This is bulukulu festival year.\n");
Also you are printing an extra newline after eof.
And btw you are indeed very careless. Look carefully there is a '.' (full-stop) after leap year. Get AC and remove your code ASAP :)
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

Crocodile_009
New poster
Posts: 4
Joined: Thu Mar 08, 2012 8:11 am

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

Post by Crocodile_009 » Thu Mar 08, 2012 8:16 am

i can't understand why my code gets WA :(
here is my code:

#include<stdio.h>
int main()
{
int year,temp;
while(scanf("%d",&year)==1)
{
printf("\n");
if( ((year%4==0)&&(year%100!=0)) ||(year%400==0) ){

printf("This is leap year.\n");
if(year%15==0){
printf("This is huluculu festival year.\n");
if(year%55==0){
printf("This is buluculu festival year.\n");
}
}
}
else if(year%15==0){
printf("This is huluculu festival year.\n");
}
else if(year%55==0&&year%100!=0){
printf("This is buluculu festival year.\n");
}
else
printf("This is an ordinary year.\n");

}
return 0;
}

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 » Thu Mar 08, 2012 11:44 pm

The input may be too large to fit into an int.
Check input and AC output for thousands of problems on uDebug!

User avatar
mahade hasan
Learning poster
Posts: 87
Joined: Thu Dec 15, 2011 3:08 pm
Location: University of Rajshahi,Bangladesh

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

Post by mahade hasan » Fri May 25, 2012 10:40 am

cut>>>>>
Last edited by mahade hasan on Thu Jun 07, 2012 4:54 am, edited 1 time in total.
we r surrounded by happiness
need eyes to feel it!

User avatar
mahade hasan
Learning poster
Posts: 87
Joined: Thu Dec 15, 2011 3:08 pm
Location: University of Rajshahi,Bangladesh

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

Post by mahade hasan » Tue May 29, 2012 2:00 pm

cut
Last edited by mahade hasan on Mon Jun 11, 2012 7:10 pm, edited 2 times in total.
we r surrounded by happiness
need eyes to feel it!

Post Reply

Return to “Volume 100 (10000-10099)”