翻箱倒柜找东西大概是所有人头痛的事情。大部分人类在识别物体的时候,更容易识别颜色而不是大小的差异。所以当我们想从一大堆杂乱堆放的长方体盒子中找到我们需要的盒子时,根据颜色找比根据尺寸找要容易。现在的问题是,我们只知道尺寸不知道颜色…… 所以就要请你从这些盒子的记录中快速找出需要的盒子的颜色。
输入格式:
输入第一行给出一个正整数 N(≤105),为盒子的总数。随后 N 行,每行列出一只盒子的长、宽、高、颜色值。再后面是查询数量 K(≤100),随后 K 行,每行给出一个需要查询的盒子的长、宽、高。
这里所有尺寸都是不超过 109 的正整数,颜色值按 RRR.GGG.BBB
格式给出,三个分值都在 [0, 255] 区间内。同一行中的数字以空格分隔。
题目保证给出的 N 只盒子的尺寸都不相同,即不存在两只盒子具有相同的长、宽、高。注意:尺寸为 1、2、3 的盒子跟尺寸为 3、2、1的盒子是不同的。
输出格式:
对每个查询的盒子,在一行中按输入相同的格式输出其颜色。如果这个尺寸的盒子不存在,则输出 Not Found
。
输入样例:
10
15 23 23 000.255.136
12 32 15 255.000.092
29 32 15 000.000.255
15 23 25 255.255.000
10 15 23 000.000.000
12 17 15 255.255.255
15 10 23 023.189.163
29 32 33 233.069.215
9 31 987 179.002.031
40 15 23 230.000.000
6
15 23 23
12 17 15
29 32 33
10 15 15
15 32 12
9 31 987
输出样例:
000.255.136
255.255.255
233.069.215
Not Found
Not Found
179.002.031
代码长度限制
16 KB
Java (javac)
时间限制
1300 ms
内存限制
256 MB
Python (python3)
时间限制
400 ms
内存限制
64 MB
其他编译器
时间限制
200 ms
内存限制
64 MB
栈限制
8192 KB
代码如下:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String he = br.readLine();
int N = Integer.parseInt(he);
String[] chicun = new String[N];
String[] yanse = new String[N];
for (int i = 0; i < N; i++) {
String da = br.readLine();
int length = da.length();
String s = da.substring(0, length - 12);
String color = da.substring(length - 11, length);
chicun[i] = s;
yanse[i] = color;
}
String s1 = br.readLine();
int K = Integer.parseInt(s1);
for (int i = 0; i < K; i++) {
String s = br.readLine();
String shuchu = "";
for (int j = 0; j < chicun.length; j++) {
if (s.equals(chicun[j])) shuchu = yanse[j];
}
if (shuchu.isEmpty()) System.out.println("Not Found");
else System.out.println(shuchu);
}
}
}