7-17 智能监测
在护理中心,智能监测仪分分钟记录着老人的各项身体指标,如果某一项指标超过了阈值范围,就会自动联系医护人员。
本题以心率为例,请你实现智能监测的功能,当发现老人的心率过缓或过急时,就发出预警信号。
输入格式:
输入在第一行中给出 2 个正整数:N(≤1000),为心率监测的数据量;T(≤20)为心率波动阈值 —— 这里我们假设在安静状态下健康成人心率大约平均 80 次/分钟,当老人的心率在区间 [80−T,80+T] 内时被认为是正常的。
随后 N 行,每行给出一个时间点和该时刻测得的心率值,格式为:时时:分分:秒秒 心率
,其中 时时
是一天内的小时数,取值区间为 [00, 23];分分
和秒秒
对应分钟数和秒数,取值区间为 [00, 59];心率
为不超过 200 的正整数。
输出格式:
按照输入的顺序检查每个给定时刻的心率,如果遇到不正常的数据,在一行中按照输入格式原样输出读到的数据。题目保证至少有一条输出。
输入样例:
tex
5 15
08:01:23 95
08:05:00 100
09:18:23 75
10:23:51 60
12:00:59 80
5 15
08:01:23 95
08:05:00 100
09:18:23 75
10:23:51 60
12:00:59 80
输出样例:
tex
08:05:00 100
10:23:51 60
08:05:00 100
10:23:51 60
Solution:
java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] input = in.readLine().split(" ");
int n = Integer.parseInt(input[0]);
int t = Integer.parseInt(input[1]);
int low = 80 - t, high = 80 + t;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
String s = in.readLine();
input = s.split(" ");
int data = Integer.parseInt(input[1]);
if (data < low || data > high) {
sb.append(s).append("\n");
}
}
System.out.print(sb);
}
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String[] input = in.readLine().split(" ");
int n = Integer.parseInt(input[0]);
int t = Integer.parseInt(input[1]);
int low = 80 - t, high = 80 + t;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
String s = in.readLine();
input = s.split(" ");
int data = Integer.parseInt(input[1]);
if (data < low || data > high) {
sb.append(s).append("\n");
}
}
System.out.print(sb);
}
}