-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path5_Question.cpp
More file actions
58 lines (41 loc) · 1.48 KB
/
5_Question.cpp
File metadata and controls
58 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Jack is always excited about sunday. It is favourite day, when he gets to play all day. And goes to cycling with his friends.
// So every time when the months starts he counts the number of sundays he will get to enjoy.
// Considering the month can start with any day, be it Sunday, Monday…. Or so on.
// Count the number of Sunday jack will get within n number of days.
// Example 1:
// Input
// mon-> input String denoting the start of the month.
// 13 -> input integer denoting the number of days from the start of the month.
// Output :
// 2 -> number of days within 13 days.
// Explanation:
// The month start with mon(Monday). So the upcoming sunday will arrive in next 6 days.
// And then next Sunday in next 7 days and so on.
// Now total number of days are 13. It means 6 days to first sunday and then remaining 7 days will end up in another sunday.
// Total 2 sundays may fall within 13 days.
#include<bits/stdc++.h>
using namespace std;
int TotalSunday(string day, int n){
unordered_map<string,int> days;
days.insert({"sun",0});
days.insert({"mon",6});
days.insert({"tue",5});
days.insert({"wed",4});
days.insert({"thu",3});
days.insert({"fri",2});
days.insert({"sat",1});
int count = 0;
int rem_days = n - days[day];
if(rem_days >= 0){
count = 1 + (rem_days / 7);
}
return count;
}
int main(){
string day;
cin>>day;
int no_of_days;
cin>>no_of_days;
cout<<TotalSunday(day,no_of_days);
return 0;
}