Page 8 of 16

Posted: Wed Mar 14, 2007 8:05 am
by Oronno
Ohh...I really do a silly mistake. Its only the spelling mistake of "bulukulu" >> "buluculu"!
Okk......thanks everyone for helping.

10070

Posted: Wed Mar 14, 2007 7:07 pm
by mnthk
Hey!

Use string to input data .... :wink:

10070

Posted: Wed Mar 14, 2007 7:08 pm
by mnthk
Hey!

Use string to input data .... :wink:

Posted: Sun Jul 29, 2007 7:47 am
by safayat rahaman
why runtime error?please help me.here is my code

Code: Select all

#include<stdio.h>
#include<string.h>
main()
{
char year[10000];
long a,b,c,d,e,l,rest,flag,sum,flag4,flag11,ten;
long arr[5];
while((l=strlen(gets(year)))>0)
{
rest=0;
flag=0;
flag4=0;
flag11=0;
for(a=0;a<=l-1;a++)
 {rest=rest*10+(year[a]-48);
  rest=rest%11;
 }
if(rest==0)
  flag11=1;
if(l<4)
{rest=0;ten=1;
for(a=l-1;a>=0;a--)
  {
  rest=(year[a]-48)*ten+rest;
  ten=ten*10;
  }
arr[1]=year[l-1]-48;
if(rest%4==0)
  if(rest%100!=0^rest%400==0)

    flag4=1;
}
else
{
for(a=1;a<=4;a++)
 {arr[a]=year[l-a]-48;}
if(arr[1]==0&&arr[2]==0)
 {
 if((arr[3]+arr[4]*10)%4==0)
  flag4=1;
 }
else
 if((arr[1]+arr[2]*10)%4==0)
  flag4=1;
}
if(flag4==1)
 {printf("This is leap year.\n");flag=1;}

if(arr[1]==0^arr[1]==5)
 {
 sum=0;
 for(a=0;a<=l-1;a++)
   sum=sum+year[a]-48;
 if(sum%3==0)
  {printf("This is huluculu festival year.\n");flag=1;}
 if(flag11==1)
  {printf("This is buluculu festival year.\n");flag=1;}
 }
if(flag==0)
 printf("This an ordinary year.\n");
}
}
[code]

Keep on getting WA - 10070 :(

Posted: Tue Aug 14, 2007 10:29 pm
by bhuwan.chopra
I tried the TC's mentioned in this thread and other threads. They seem to be fine. I keep on getting WA. Also i have taken care of long length numbers.

Code: Select all

# include <iostream>
# include <string>

using namespace std;
string str;
bool mod4(string str)
{
	int l = str.size();
	int no = (str[l-2]-'0')*10 + (str[l-1]-'0');
	return (no%4==0);
}

bool mod100()
{
	int l = str.size();
	int no = (str[l-2]-'0')*10 + (str[l-1]-'0');
	return (no==0);
}

bool mod400()
{
	int l = str.size();
	return ( mod100() && mod4(str.substr(0,l-2)));
}

bool mod3()
{
	int sum = 0;
	for(int i=0;str[i];i++)
		sum+=(str[i]-'0');
	return (sum%3==0);
}

bool mod5()
{
	int l = str.size();
	return (str[l-1]=='0'||str[l-1]=='5');
}

bool mod11()
{
	int sum = 0,pow=1;
	for(int i=0;str[i];i++,pow*=-1)
		sum+=(pow*(str[i]-'0'));
	return (sum%11==0);
}

bool mod15()
{
	return (mod3() && mod5());
}

bool mod55()
{
	return (mod5() && mod11());
}

int main()
{
	int ca=1;
	while(cin>>str)
	{
		if(ca!=1)
			cout<<endl;
		ca++;
		bool l = false;
		bool p = false;
		if(mod400()||(mod4(str)&&!mod100()))
		{
			cout<<"This is leap year."<<endl;
			l=true;
			p=true;
		}
		if(mod15())
		{
			cout<<"This is huluculu festival year."<<endl;
			p=true;
		}
		if(l&&mod55())
		{
			cout<<"This is bulukulu festival year."<<endl;
			p=true;
		}
		if(!p)
			cout<<"This is an ordinary year."<<endl;
	}
	return 0;
}
Thanks,
Bhuwan

Posted: Sat Feb 09, 2008 12:48 pm
by Bitta
I am getting WA.Pls help!!!Here is my code...

Code: Select all

#include<stdio.h>
#include<string.h>
#define max 10000

int main (void)

{	char a[max];
	int i,sum1,sum2,p,q,r,s,e,f,g;
	

	while(scanf("%s",&a)==1)

	{	p=strlen(a)-1;
		sum1=0;
		sum2=0;
		q=0;
		r=0;
		s=0;
		e=0;
		f=0;
		g=0;

		for(i=0;i<=p;i+=2)
		{	sum1+=(a[i]-'0');
		}

		for(i=1;i<=p;i+=2)
		{	sum2+=(a[i]-'0');
		}

		if(((a[p]-'0')+((a[p-1]-'0')*10))%4==0)
		{	e=1;
		}

		if(a[p]=='0' || a[p-1]=='0')
		{	f=1;
		}

		if(a[p]=='0' && a[p-1]=='0' && ((a[p-2]-'0')+((a[p-3]-'0')*10))%4==0)
		{	g=1;
		}


		if((e==1 && f!=1)|| g==1)
		{	printf("This is leap year.\n");
			q=1;
		}
	
		if((a[p]=='5'||a[p]=='0') && ((sum1+sum2)%3==0))
		{	printf("This is hulukulu festival year.\n");
			r=1;
		}
		if((a[p]=='5'||a[p]=='0') && ((sum1-sum2)%11==0) && q==1)
		{	printf("This is bulukulu festival year.\n");
			s=1;
		}

		if(q==0 && r==0 && s==0)
		{	printf("This is an ordinary year.\n");
		}

		printf("\n");
	}

	return 0;
}
[Edited by : Jan] Use code tags

Posted: Sat Feb 09, 2008 8:46 pm
by Jan
Check your spelling carefully and try the case.

Input:

Code: Select all

4248035245857302861304475122262852382232831183377907185400973044372526725256648804647567360
Output:

Code: Select all

This is leap year.
This is huluculu festival year.
This is bulukulu festival year.
Hope these help.

Re: Problem 10070 leap year...

Posted: Mon Apr 28, 2008 1:09 pm
by amit_chauhan
Hi Friends i am getting run time error. Plz help me..........

Code

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


int main()
{
char year[10000000];
int flag=0,i=0;
int mod4,mod100,mod400,mod15,mod55;

while (1)
{

if (fgets(year,sizeof(year),stdin)==NULL) break;

mod4=mod100=mod400=mod15=mod55=0;

if(flag==0) flag=1;
else printf("\n");

for (i=0;i<strlen(year)-1;i++)
{
mod4=(mod4*10+year-'0')%4;
mod100=(mod100*10+year-'0')%100;
mod400=(mod400*10+year-'0')%400;
mod15=(mod15*10+year-'0')%15;
mod55=(mod55*10+year-'0')%55;
}

if((mod4==0 && mod100!=0)||( mod400==0))
{
printf("This is leap year.\n");
if(mod15==0)
printf("This is huluculu festival year.\n");
if(mod55==0)
printf("This is bulukulu festival year.\n");
}
else
{
if(mod15==0)
printf("This is huluculu festival year.\n");
else
printf("This is an ordinary year.\n");
}

}

return 0;
}

Re: Problem 10070 leap year...

Posted: Mon Apr 28, 2008 5:32 pm
by Jan
If you want to declare a big array, make it global rather than local.

Re: Problem 10070 leap year...

Posted: Tue Apr 29, 2008 8:27 pm
by amit_chauhan
@Jan

Thanks a lots Bro I got accepted...........

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

Posted: Wed Jul 02, 2008 1:30 pm
by scorpio
its an easy prob. 8) but i keep getting WA :oops: in it.here is my code:

Code: Select all

#include<stdio.h>
int main()
{
	char a[100001];
	int b,c,d,e,f,x,i,y,p,q;
	while(gets(a))
	{
		b=c=d=e=f=p=q=x=0;
		for(i=0;a[i];i++)
		{
			b=(b*10+a[i]-48)%4;
			c=(c*10+a[i]-48)%100;
			d=(d*10+a[i]-48)%400;
			e=(e*10+a[i]-48)%15;
			f=(f*10+a[i]-48)%55;
		}
		if(y==1)
			printf("\n");
		if((b==0&&c!=0)||d==0)
		{
			x=y=1;
			printf("This is leap year.\n");
		}
		if(e==0)
		{
			y=p=1;
			printf("This is huluculu festival year.\n");
		}
		if(x==1&&f==0)
		{
			y=q=1;
			printf("This is bulukulu festival year.\n");
		}
		if(x==0&&p==0&&q==0)
		{
			y=1;
			printf("This is an ordinary year.\n");
		}		
	}
	return 0;
}
can anyone give some sample I/O..or pls tell me where i missing thingz...Thanx in advance :P

Re: runtime error

Posted: Mon Oct 06, 2008 6:18 pm
by lnr
Runtime error occurs when your code fails to run for an input in running time.
It may happen when
1.the array size is small
2.index out of range for an array
3.divide by zero
and others .....

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

Posted: Sun May 09, 2010 11:35 pm
by eendro
# include<stdio.h>
int main()
{
int y,tmp,h;
while(scanf("%d", &y)==1)
{
h=0;
tmp=0;
if((y%400==0)||(y%100!=0)&&(y%4==0))
{
printf("This is leap year.\n");
tmp=1;
}

if(y%15==0)
{
printf("This is huluculu festival year.\n");
h=1;
}

if((y%55==0)&&(tmp==1))
{
printf("This is buluculu festival year.\n");
}

if((tmp!=1)&&(h!=1))
{
printf("This is an ordinary year.\n");
}
printf("\n");
}
return 0;
}





what is the wrong here?????

Re:

Posted: Sat May 15, 2010 1:56 pm
by iceb3rg
problem wrote:[c]....
..............
...........
...............


my output
==========

This is Leap year.

This is Leap year.
This is huluculu festival year.

This is huluculu festival year.

This is ordinary year.

This is Leap year.
This is buluculu festival year.

This is ordinary year.

This is Leap year.
This is buluculu festival year.

This is Leap year.
This is huluculu festival year.
This is buluculu festival year.

This is huluculu festival year.

This is Leap year.
This is buluculu festival year.

This is Leap year.

This is ordinary year.

This is ordinary year.

This is ordinary year.

--This is Leap year. //15 th is not match of actual output.
--This is buluculu festival year.

This is ordinary year.

This is Leap year.
This is huluculu festival year.

This is huluculu festival year.

This is Leap year.

This is ordinary year.

This is ordinary year.

This is huluculu festival year.

This is Leap year.
This is huluculu festival year.

This is ordinary year.

This is huluculu festival year.

This is huluculu festival year.

This is huluculu festival year.

This is huluculu festival year.

This is ordinary year.

This is Leap year.

This is Leap year.
This is huluculu festival year.

This is huluculu festival year.

This is ordinary year.



but actual output is::
========================


This is leap year.

This is leap year.
This is huluculu festival year.

This is huluculu festival year.

This is an ordinary year.

This is leap year.
This is bulukulu festival year.

This is an ordinary year.

This is leap year.
This is bulukulu festival year.

This is leap year.
This is huluculu festival year.
This is bulukulu festival year.

This is huluculu festival year.

This is leap year.
This is bulukulu festival year.

This is leap year.

This is an ordinary year.

This is an ordinary year.

This is an ordinary year.

==This is leap year. //NOT MATCH IN MY OUTPUT//

This is an ordinary year.

This is leap year.
This is huluculu festival year.

This is huluculu festival year.

This is leap year.

This is an ordinary year.

This is an ordinary year.

This is huluculu festival year.

This is leap year.
This is huluculu festival year.

This is an ordinary year.

This is huluculu festival year.

This is huluculu festival year.

This is huluculu festival year.

This is huluculu festival year.

This is an ordinary year.

This is leap year.

This is leap year.
This is huluculu festival year.

This is huluculu festival year.

This is an ordinary year.


HELP ME PLZ.
[\c]

Hey dude.....There's a lot of spelling mistake out there...."Leap" should be "leap" and "buluculu" should be "bulukulu" - note the Big L and K here !....That may help ! :)

WA: Any special test cases?

Posted: Sat May 15, 2010 9:08 pm
by iceb3rg
#include <stdio.h>
#include <string.h>

char name[100000];
int t;
int save[100000];
int i,ans;
int a=0;

int chk(int t)
{
a=0;
int rem=0;

//scanf ("%d",&t);

int num=0;



for (i=0;name!='\0';i++)
{



while (1)
{
num=num*10;
num+=name-48 ;

if (num==0)
break;

//printf ("# num = %d i = %d\n",num,i);

if (num>=t)
break;
else
{
i++;
if (i>strlen(name)-1)
break;
//num=num*10;
}

}

if (num==0)
{
ans=0;
save[a++]=ans;
//printf ("num = %d ans = %d\n",num,ans);
save[a]='\0';
}
else
{
ans=num/t;


save[a++]=ans;
//printf ("num = %d ans = %d\n",num,ans);
save[a]='\0';

ans=num%t;
num=ans;

if (num!=0 && name[i+1]=='\0')
{
//printf ("Remainder left = %d\n",num);
rem=1;
}
else
rem=0;
}
}

return rem;

}

int main()
{

//freopen("input4uva.txt","r",stdin);

int y=0;

while (scanf ("%s",name)!=EOF)
{
int stat,leap=0,stat2;

if (y==0)
y++;
else
printf ("\n");
//puts(save);

/*
for (int z=0;z<a;z++)
printf ("%d",save[z]);
printf ("\n");
*/
int hul=1,bul=1;

//stat=chk(400);

//if (stat==0)
// leap=1;
//else


// ekhane change

{
stat=chk(4);
stat2=chk(100);
int stat3=chk(400);

if ((stat==0 && stat2==1 )|| stat3==0)
leap=1;
}
//printf ("res %d\n",stat);

int lp=0,fv=0;

if (leap==1)
{
printf ("This is leap year.\n");
lp=1;
}



hul=chk(15);
bul=chk(55);



if (hul==0)
{
printf ("This is huluculu festival year.\n");
fv=1;
}



if (leap==1 && bul==0)
{
printf ("This is bulukulu festival year.\n");
fv=1;
}

if (lp==0 && fv==0)
printf ("This is an ordinary year.\n");






}
return 0;
}

######################################################################################################################
Hi, I am struggling with this problem..can any 1 tell me where am i going wrong....any test cases to put me on track?