Print the day for a given date. ID:213


The day corresponding to the first date of a given month is provided as input to the program. Then a specific date D of the month is provided. The program must  print the day (one among MON,TUE, WED, THU, FRI, SAT, SUN) of the date D.

Input Format:
First line will contain the day (one among MON,TUE, WED, THU, FRI, SAT, SUN) of the first date of the month.
Second line will contain the value of the date D as an integer value.

Output Format:
First line will contain the day of the date D


Sample Input/Output:

Example 1:
Input:
MON
10

Output:
WED

Explanation:
If it is Monday on 1st of the month, then 10th of the month will be a Wednesday. Hence WED is printed.


Example 2:

Input:
FRI
24

Output:
SUN

Explanation:
If it is Friday on 1st of the month, then 22nd will also be a Friday. Hence 24th of the month will be a Sunday. Hence SUN is printed.

PROGRAM:

#include <bits/stdc++.h>
#include<string.h>
using namespace std;

int main(int argc, char** argv)
{
char s[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
char s1[4];int a,d=-1;
cin>>s1>>a;
for(int i=0;i<7;i++)
{
    if(strcmp(s[i],s1)==0)
    {
        d=i;
    }
}
int f=d+a;
if(f%7==0)
cout<<"SUN";
else if(f%7==1)
cout<<"MON";
else if(f%7==2)
cout<<"TUE";
else if(f%7==3)
cout<<"WED";
else if(f%7==4)
cout<<"THU";
else if(f%7==5)
cout<<"FRI";
else if(f%7==6)
cout<<"SAT";
}

Comments

Popular Posts