Atcoder TOYOTA SYSTEMS Programming Contest 2021(AtCoder Beginner Contest 228) A - On and Off

韩靖琪
2023-12-01

题目链接:A - On and Off (atcoder.jp)

Problem Statement

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.

Constraints

  • 0≤S,T,X≤23
  • S !=T
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

S T X

Output

If the light is on at 3030 minutes past XX o'clock, print Yes; otherwise, print No.


Sample Input 1 Copy

7 20 12

Sample Output 1 Copy

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.


Sample Input 2 Copy

20 7 12

Sample Output 2 Copy

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.


Sample Input 3 Copy

23 0 23

Sample Output 3 Copy

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;
}

 类似资料: