Page 9 of 16
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Sun Jun 06, 2010 3:28 pm
by aaa111
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;
}
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Thu Jun 10, 2010 10:32 pm
by sazzadcsedu
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.
10070 - Why only huluculu
Posted: Sun Aug 22, 2010 10:27 am
by yeasin_acm_solver
/*************************************************************/
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..
10070 Why wrong answer this code
Posted: Sun Aug 22, 2010 9:12 pm
by yeasin_acm_solver
/*************************************************************/
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..
Re: 10070 - Why only huluculu
Posted: Mon Aug 23, 2010 4:53 pm
by sazzadcsedu
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.
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Fri Feb 25, 2011 9:17 am
by Eather
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();
}
}
}
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Mon Mar 28, 2011 4:13 pm
by tanvir09
I don't know why am i getting wrong answer, i checked all output,they seems right to me
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;
}
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Thu Apr 28, 2011 6:15 pm
by Mohayemin
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);
}
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Tue Jun 07, 2011 8:17 pm
by nonamebd
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;
}
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Mon Jun 27, 2011 8:36 pm
by plamplam
There is no blank line after the last output.

Re: 10070 - Leap Year or Not Leap Year and …
Posted: Tue Jun 28, 2011 5:03 am
by plamplam
@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

Re: 10070 - Leap Year or Not Leap Year and …
Posted: Thu Mar 08, 2012 8:16 am
by Crocodile_009
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;
}
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Thu Mar 08, 2012 11:44 pm
by brianfry713
The input may be too large to fit into an int.
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Fri May 25, 2012 10:40 am
by mahade hasan
cut>>>>>
Re: 10070 - Leap Year or Not Leap Year and …
Posted: Tue May 29, 2012 2:00 pm
by mahade hasan
cut