Saturday, 25 August 2012

PLAY WITH DATES


Play with dates


Problem Statement:

Given the date, month and year, find the day.

Input Specification:

The first line consists of an integer t, the number of test cases. Then for each test case there are three integers the date, month and year.

Output Specification:

For each test case print the day in words in a separate line(The first character should be caps followed by small letters).

Input Constraints:

1<=t<=100

Date/month/year >= 11/1/2012

Date/month/year<=31/12/3000

The given date will always be a valid date

Sample Input:

3

11 1 2012

12 1 2012

13 1 2012

Sample Output:

Wednesday

Thursday

Friday


SOLUTION--------------




#include
int main()
{
        unsigned long long int t,i,day,month,year,total_days,Y,M;
        scanf("%llu",&t);
        while(t--)
        {
                int arr[13];
                arr[1]=31,arr[2]=28,arr[3]=31,arr[4]=30,arr[5]=31,arr[6]=30,arr[7]=31,arr[8]=31,arr[9]=30,arr[10]=31,arr[11]=30,arr[12]=31;
                total_days=0;
                scanf("%llu %llu %llu",&day,&month,&year);
                Y=1900,M=1;
                if(year>1900)
                {
                        while(Y
                        {
                        if((Y%4==0&&Y%100!=0)||Y%400==0)
                        {
                                total_days+=366;
                        }
                        else{
                                total_days+=365;
                        }
                        Y=Y+1;
                        }
                }
                        if(month>1){
                        for(M=1;M
                        {
                                if(M==2)
                                {
                                if((Y%4==0&&Y%100!=0)||Y%400==0){
                                total_days+=29;
                                }
                                }
                                else
                                total_days+=arr[M];
                        }
                        }
                        total_days+=day;
                    
                        i=total_days%7;
                
                        if(i==0)
                                printf("Sunday\n");
                        if(i==1)
                                printf("Monday\n");
                        if(i==2)
                                printf("Tuesday\n");
                        if(i==3)
                                printf("Wednesday\n");
                        if(i==4)
                                printf("Thursday\n");
                        if(i==6)
                                printf("Saturday\n");
                        if(i==5)
                                printf("Friday\n");
        }
        return 0;
}



2 comments:

Unknown said...

#include
#include
void main()
{
int a,b,c,d,e,x,y,z;
int i;
int j;
printf ("enter the date");
scanf ("%d %d %d",&z,&y,&x);
i=0;
int k;
for (a=1900;a<=x;a++)
{ if(a==x)
{
j=y;
}
else
{
j=12;
}
for (b=1;b<=j;b++)
{
if (b==1||b==3||b==5||b==7||b==8||b==10||b==12)
d=31;
if (b==4||b==6||b==9||b==11)
d=30;
if (a%400==0||a%100!=0&&a%4==0)
{
if (b==2)
{
d=29;
}


}
else
{
if (b==2)
{
d=28;
}
}
if(a==x&&b==y)
{
d=z;
}
for (k=1;k<=d;k++)
{
i = i+1;
}
}
}
i=i%7;
if (i==0)
{
printf ("SUNDAY");
}
if (i==1)
{
printf ("MONDAY");
}
if (i==2)
{
printf ("TUESDAY");
}
if (i==3)
{
printf ("WEDNESDAY");
}
if (i==4)
{
printf ("THURSDAY");
}
if (i==5)
{
printf ("FRIDAY");
}
if (i==6)
{
printf ("SATURDAY");
}

}

CHANDAN SINGH said...

thanxx ARCHIT ATTRI !!!!
THANXX for make my solution correct!!