Official
A - Rainy Season Editorial by evima
In the first place, there are only \(2^3 = 8\) combinations of weather: for each of the first, second and third days, the whether is either sunny or rainy.
For example, you can get the correct answer by checking in the following order:
- check if there are \(3\) consecutive rainy days
- check if there are \(2\) consecutive rainy days
- check if there is \(1\) consecutive rainy day
- otherwise (\(0\) days)
This way, you can avoid mistakes, and moreover it is extensible to the input more than three days.
#include <iostream>
using namespace std;
int main() {
string S;
cin >> S;
bool p = S[0] == 'R';
bool q = S[1] == 'R';
bool r = S[2] == 'R';
if (p and q and r) {
cout << 3 << endl;
} else if ((p and q) or (q and r)) {
cout << 2 << endl;
} else if (p or q or r) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
return 0;
}
posted:
last update: