题目链接:A - On and Off (atcoder.jp)
Takahashi turns on the light of his room at S o'clock (on the 2424-hour clock) every day and turns it off at T o'clock every day.
The date may change while the light is on.
Determine whether the light is on at 30 minutes past X o'clock.
Input is given from Standard Input in the following format:
S T X
If the light is on at 3030 minutes past XX o'clock, print Yes
; otherwise, print No
.
7 20 12
Yes
The light is on between 77 o'clock and 2020 o'clock. At 3030 minutes past 1212 o'clock, it is on, so we print Yes
.
20 7 12
No
The light is on between 00 o'clock and 77 o'clock, and between 2020 o'clock and 00 o'clock (on the next day). At 3030 minutes past 1212 o'clock, it is off, so we print No
.
23 0 23
Yes
题意:一个人在s点的时候打开灯,在t点的时候关灯,然后判断一下x点30min的时候灯是否开着(s, t不一定在同一天)
思路:通过s,t的值判断是否在同一天:s < t的时候在同一天,否则为两天,然后判断x点30min在范围内即可
#include<bits/stdc++.h>
using namespace std;
int main(){
int s, t, x;
while(cin >> s >> t >> x){
if(s < t){
if(x >= s && x < t){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}else{
if((x >= s && x < 24) || (x >= 0 && x < t)){
cout << "Yes" << endl;
}else{
cout << "No" << endl;
}
}
}
return 0;
}