🌕🌑🌑🌑🌑
# 題目連結
- 題目連結
- Online Judge
- uDebug
# 題目說明
Time limit: 3.000 seconds
# 題目
Auto-mobile Charting & Manufacturing (ACM) is a company that specializes in manufacturing automobile spare parts. Being one of the leading automotive companies in the world, ACM are sure to keep up the latest information in that world. In the 100-year anniversary of the company, ACM compiled a huge list of range of prices of any automobiles ever recorded in the history. ACM then wants to develop a program that they called Automobile Expert System or AES for short.
The program receives a price P as an input, and searches through the database for a car maker in which P falls in their range of lowest price L and highest price H of car they ever made. The program then output the car maker name. If the database contains no or more than one car maker that satisfies the query, the program produce output ‘UNDETERMINED’ (without quotes). Not so expert, huh? You are about to develop that program for ACM.
# Input
The input begins with a line containing an integer T (T ≤ 10)
, the number of test cases follow. Each case begins with the size of the database D (D < 10000)
. The next each of D
lines contains M
, L
and H (0 < L < H < 1000000)
which are the name of the maker (contains no whitespace and will never exceeds 20
characters), the car’s lowest price the maker ever made, and the car’s highest price the maker ever made respectively. Then there is the number of query Q (Q < 1000)
follows. Each of the next Q
lines contains an integer P (0 < P < 1000000)
, the query price.
# Output
Output for each query should be one line containing the name of the maker, or the string ‘UNDETERMINED’ (without quotes) if there is no maker or more than one maker that satisfies the query. You should separate output for different case by one empty line.
# Sample Input
1
4
HONDA 10000 45000
PEUGEOT 12000 44000
BMW 30000 75900
CHEVROLET 7000 37000
4
60000
7500
5000
10000
# Sample Output
BMW
CHEVROLET
UNDETERMINED
UNDETERMINED
# 解題技巧
# Solution
import java.util.*; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int T = sc.nextInt(); | |
for (int i = 0; i < T; i++) { | |
if (i != 0) { | |
System.out.println(); | |
} | |
int D = sc.nextInt(); | |
Map<String, int[]> map = new HashMap<>(); | |
for (int j = 0; j < D; j++) { | |
String M = sc.next(); | |
int[] LH = new int[2]; | |
LH[0] = sc.nextInt(); | |
LH[1] = sc.nextInt(); | |
map.put(M, LH); | |
} | |
int Q = sc.nextInt(); | |
for (int j = 0; j < Q; j++) { | |
int P = sc.nextInt(); | |
boolean isOutput = false; | |
String output = " "; | |
for (String M : map.keySet()) { | |
int[] LH = map.get(M); | |
if (P >= LH[0] && P <= LH[1]) { | |
if(isOutput){ | |
isOutput = false; | |
break; | |
} | |
isOutput = true; | |
output = M; | |
} | |
} | |
System.out.println((isOutput ? output : "UNDETERMINED")); | |
} | |
} | |
sc.close(); | |
} | |
} |
單字
** **
!! !!
片語 & 搭配詞
!! !!