-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path041_Quarter_of_the_year.cpp
61 lines (41 loc) · 1.09 KB
/
041_Quarter_of_the_year.cpp
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
59
60
61
/*
Codewars Coding Challenge
Quarter of the year
Given a month as an integer from 1 to 12, return to which quarter of the year it belongs as an integer number.
For example: month 2 (February), is part of the first quarter; month 6 (June), is part of the second quarter; and month 11 (November), is part of the fourth quarter.
Constraint:
1 <= month <= 12
int quarter_of(int month){
return 0;
}
https://www.codewars.com/kata/5ce9c1000bab0b001134f5af/train/cpp
*/
// #include <iostream>
// using namespace std;
// My Solution
int quarter_of(int month){
return (month - 1) / 3 + 1;
}
// int main(){
// cout << quarter_of(7) << endl;
// return 0;
// }
/*
Sample Tests
Describe(Sample_tests) {
It(Base_cases) {
Assert::That(quarter_of(1), Equals(1));
Assert::That(quarter_of(3), Equals(1));
Assert::That(quarter_of(5), Equals(2));
Assert::That(quarter_of(7), Equals(3));
Assert::That(quarter_of(9), Equals(3));
Assert::That(quarter_of(11), Equals(4));
}
};
*/
/*
Perfect Solution From Codewars
int quarter_of(int month){
return (month + 2) / 3;
}
*/