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

lbv
Experienced poster
Posts: 128
Joined: Tue Nov 29, 2011 8:40 am

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

Post by lbv »

hello wrote:Why got WA......please help.....
Hi,
  • To post code, please use the "code" tags (see the button bar above the message editor).
  • I suggest you start by taking the time to read the previous messages from this thread. There's a lot of noise, but also it's easy to spot the useful messages, with tips and test cases for you to try.
  • Maybe the number in the input has more than 10^5 characters? My program assumes a maximum number of digits of about 10^6.
Try this case:

Input

Code: Select all

2100
Output

Code: Select all

This is huluculu festival year.
hello
New poster
Posts: 25
Joined: Sun Mar 10, 2013 7:29 pm

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

Post by hello »

Code: Select all

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

int main()
{

    int c15,c55,c100,c400,c4,ct=1,l,r,t;
    char arr[1000000];
    while(scanf("%s",arr)==1)
    {
        int i,k,q=0,rem=0,m=0,x=0,y=0;
        i=strlen(arr);
        for(k=0; k<i; k++)
        {
            rem=rem*10;
            rem+=arr[k]-48;
            rem=rem%55;
            q=q*10;
            q+=arr[k]-48;
            q=q%4;
            m=m*10;
            m+=arr[k]-48;
            m=m%15;
            x=x*10;
            x+=arr[k]-48;
            x=x%100;
            y=y*10;
            y+=arr[k]-48;
            y=y%400;

        }

        if (rem==0)c55=1; else c55=0;
        if (q==0)c4=1;else c4=0;
        if(m==0)c15=1;else c15=0;
        if(x==0)c100=1;else c100=0;
        if(y==0)c400=1;else c400=0;
        if(c4 && (!c100 || c400))l=1;else l=0;


        if(ct!=1)printf("\n");
        if(l){printf("This is leap year.\n");}
        if(c15)printf("This is huluculu festival year.\n");
        if(l && c55)printf("This is bulukulu festival year.\n");
        if(c4==0 && c15==0)printf("This is an ordinary year.\n");
        ct++;
    }
    return 0;

}
still got WA..... Please Someone help me....
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 »

Input: 2200
AC output: This is an ordinary year.
Check input and AC output for thousands of problems on uDebug!
nildorpon
New poster
Posts: 4
Joined: Sun Jul 21, 2013 4:13 pm

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

Post by nildorpon »

I got a Compile error.
Please take a look on my code and tell me whats wrong....

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Main {
public static void main(String [] args){
Scanner scanner = new Scanner(new BufferedInputStream(System.in));
while(scanner.hasNext()){
int n = scanner.nextInt();
if(n<2000){
continue;
}
if(((n%4 == 0) && (n%100 != 0)) || (n%400 == 0)){
System.out.println("This is leap year.");
if(n%15 == 0){
System.out.println("This is huluculu festival year.");
}
if(n%55 == 0){
System.out.println("This is Bulukulu festival year.");
}
}else if(n%15 == 0){
System.out.println("This is huluculu festival year.");
}else{
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 »

You can click My Submissions to see the reason for your Compile Error. That code however gets RE. Try using BigInteger.
Check input and AC output for thousands of problems on uDebug!
f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

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

Post by f.maru »

Hi guys, this is my program it gave true answer for all test case but i got WA can sb help me plzzzz

Code: Select all

#include<iostream>
#include <math.h>
#include <cmath>
#include <string>
using namespace std;
int sum,m1,m2;
void sumi(string v)
{
     m1=m2=sum=0;
     for (int t=0;t<v.length();t++)
     {
         if (t%2==0)
            m1+=v[t]-48;
         else
            m2+=v[t]-48;
         sum+=v[t]-48;         
     }
}
int main()
{
    string n;
    while(cin>>n)
    {
                 sumi(n);
                 int w=0,ls=0,p1=n[n.length()-1]-48,p2=n[n.length()-2]-48,p3=n[n.length()-3]-48,p4=n[n.length()-4]-48;
                 if((p2*10+p1)%4==0 && p1+p2!=0 ||(p4*10+p3)%4==0 && p1+p2==0)
                 {
                                    w=ls=1;
                                    cout<<"This is leap year."<<endl;
                 }  
                 if(sum %3==0 & p1 % 5==0)
                 {
                                    w=1;
                                    cout<<"This is huluculu festival year."<<endl;
                 }  
                 int m=abs(m1-m2);
                 if(p1 % 5==0 && m%11==0 && ls==1)  
                 {
                                    w=1;
                                    cout<<"This is bulukulu festival year."<<endl;
                 }   
                 if(w==0)
                 cout<<"This is an ordinary year."<<endl;
                 cout<<endl;                         
    }
}
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 »

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!
f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

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

Post by f.maru »

So how can i notice if it is the last case
and i think i cant use this

Code: Select all

#include<iostream>
#include <math.h>
#include <cmath>
#include <string>
using namespace std;
int sum,m1,m2;
void sumi(string v)
{
     m1=m2=sum=0;
     for (int t=0;t<v.length();t++)
     {
         if (t%2==0)
            m1+=v[t]-48;
         else
            m2+=v[t]-48;
         sum+=v[t]-48;         
     }
}
int main()
{
    string n;
    cin>>n;
                     sumi(n);
                 int w=0,ls=0,p1=n[n.length()-1]-48,p2=n[n.length()-2]-48,p3=n[n.length()-3]-48,p4=n[n.length()-4]-48;
                 if((p2*10+p1)%4==0 && p1+p2!=0 ||(p4*10+p3)%4==0 && p1+p2==0)
                 {
                                    w=ls=1;
                                    cout<<"This is leap year."<<endl;
                 }  
                 if(sum %3==0 & p1 % 5==0)
                 {
                                    w=1;
                                    cout<<"This is huluculu festival year."<<endl;
                 }  
                 int m=abs(m1-m2);
                 if(p1 % 5==0 && m%11==0 && ls==1)  
                 {
                                    w=1;
                                    cout<<"This is bulukulu festival year."<<endl;
                 }   
                 if(w==0)
                 cout<<"This is an ordinary year."<<endl; 
    while(cout<<endl && cin>>n)
    {

                 sumi(n);
                 int w=0,ls=0,p1=n[n.length()-1]-48,p2=n[n.length()-2]-48,p3=n[n.length()-3]-48,p4=n[n.length()-4]-48;
                 if((p2*10+p1)%4==0 && p1+p2!=0 ||(p4*10+p3)%4==0 && p1+p2==0)
                 {
                                    w=ls=1;
                                    cout<<"This is leap year."<<endl;
                 }  
                 if(sum %3==0 & p1 % 5==0)
                 {
                                    w=1;
                                    cout<<"This is huluculu festival year."<<endl;
                 }  
                 int m=abs(m1-m2);
                 if(p1 % 5==0 && m%11==0 && ls==1)  
                 {
                                    w=1;
                                    cout<<"This is bulukulu festival year."<<endl;
                 }   
                 if(w==0)
                 cout<<"This is an ordinary year."<<endl;                         
    }
}
but i still get WA
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 »

A blank line should separate the output for each line of input. Don't print an extra blank line at the end.
One way to do that would be:

Code: Select all

bool first = true;
while(cin >> n) {
  if(!first)
    cout << endl;
  first = false;

  //the rest of your code goes here
}
Check input and AC output for thousands of problems on uDebug!
f.maru
New poster
Posts: 13
Joined: Wed Jul 31, 2013 2:27 pm

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

Post by f.maru »

TNX brianfry713 i got ac
Salam!
New poster
Posts: 7
Joined: Tue Sep 10, 2013 7:14 pm

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

Post by Salam! »

Hi Guys
I Don't Understand why I get wa
plz help Meeeeeeee :wink:

Code: Select all

I Got Ac...
Last edited by Salam! on Fri Sep 13, 2013 10:49 pm, edited 1 time in total.
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 »

You misspelled bulukulu
Check input and AC output for thousands of problems on uDebug!
Salam!
New poster
Posts: 7
Joined: Tue Sep 10, 2013 7:14 pm

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

Post by Salam! »

brianfry713 wrote:You misspelled bulukulu
Thanks Brianfry713 I got ac
ijabir
New poster
Posts: 3
Joined: Thu Sep 26, 2013 5:42 pm

Getting WA - UVA 10070 -Leap Year or Not Leap Year and …

Post by ijabir »

here is my code. help me out

Code: Select all

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

using namespace std;

int mod(string s, int n)
{
    int i=0, rem=0, sz=s.size();

    while(i<sz)
    {
        rem=rem*10+(s[i]-'0');
        rem%=n;
        i++;
    }
    return rem%n;
}

int main()
{
    int t, cs=0, f, y, r4, r100, r400, r15, r55;
    string s;
    while(getline(cin,s))
    {
        t=0;
        f=0;
        r4=mod(s, 4);
        r100=mod(s, 100);
        r400=mod(s, 400);
        r15=mod(s, 15);
        r55=mod(s, 55);
        //printf("%d %d %d %d %d", r4, r100, r400, r15, r55);
        if(r15==0) t=1;
        if(r400==0 || (r4==0 && r100!=0))
        {
            printf("This is leap year.\n");
            if(t==1)
            {
                printf("This is huluculu festival year.\n");
                t=0;
            }
            if(r55==0) printf("This is bulukulu festival year.\n");
            f=1;
        }
        if(t==1)
        {
            printf("This is huluculu festival year.\n");
            f=1;
        }
        if(f==0) printf("This is an ordinary year.\n");
        printf("\n");
    }

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

Re: Getting WA - UVA 10070 -Leap Year or Not Leap Year and …

Post by brianfry713 »

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!
Post Reply

Return to “Volume 100 (10000-10099)”