Problem Description
"Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date. You are required to find a day from a particular date given to you.
Input
It consists of a single line entry consisting of date in format dd mm yyyy. i.e. the input line consists of the three numbers written in order followed by spaces. Eg. Input for 18-12-1990 is be written as 18 12 1990
Output
It consists of single line output showing the day for that particular date.
"Test Case 1
Input (stdin)14 3 2012
Expected OutputWednesday
Test Case 2
Input (stdin)25 01 2011
Expected OutputTuesday
Program
#include<stdio.h> char * day[] ={"Sunday", "Monday","Tuesday", "Wednesday","Thursday", "Friday", "Saturday"}; int solve(int y, int m, int d) { static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; y -= m < 3; return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; } int main() { int d, m, y; scanf("%d%d%d",&d,&m,&y); int w = solve(y, m, d); printf("%s\n",day[w]); return 0; }
No comments:
Post a Comment
Note: only a member of this blog may post a comment.