UVa1237 - Expert Enough?(枚举)

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 Pfalls 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$ \le$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
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;

public class Main implements Runnable
{
	private static final boolean DEBUG = false;
	private BufferedReader cin;
	private StreamTokenizer tokenizer;
	private PrintWriter cout;
	private int d;
	private Car[] cars;
	
	class Car
	{
		String name;
		int low, high;
	}
	
	private void init()
	{
		try {
			if (DEBUG) {
				cin = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\OJ\\uva_in.txt")));
			} else {
				cin = new BufferedReader(new InputStreamReader(System.in));
			}
			
			tokenizer = new StreamTokenizer(cin);
			cout = new PrintWriter(new OutputStreamWriter(System.out));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private String next()
	{
		try {
			tokenizer.nextToken();
			if (tokenizer.ttype == StreamTokenizer.TT_EOF) return null;
			else if (tokenizer.ttype == StreamTokenizer.TT_NUMBER) {
				return String.valueOf((int)tokenizer.nval);
			} else return tokenizer.sval;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	private void input()
	{
		d = Integer.parseInt(next());
		
		cars = new Car[d];
		for (int i = 0; i < d; i++) {
			cars[i] = new Car();
			cars[i].name = next();
			cars[i].low = Integer.parseInt(next());
			cars[i].high = Integer.parseInt(next());
		}
	}
	
	private void solve(int cas)
	{
		int q = Integer.parseInt(next());
		for (int i = 0; i < q; i++) {
			int p = Integer.parseInt(next());
			int ans = 0;
			String name = null;
			
			for (int j = 0; j < d; j++) {
				if (cars[j].low <= p && cars[j].high >= p) {
					name = cars[j].name;
					ans++;
				}
			}
			
			if (ans == 1) {
				cout.println(name);
			} else cout.println("UNDETERMINED");
		}
		
		if (cas != 0) cout.println();
		
		cout.flush();
	}
	
	public void run()
	{
		init();
		
		int t = Integer.parseInt(next());
		while (t-- > 0) {
			input();
			solve(t);
		}
	}
	
	public static void main(String[] args)
	{
		new Thread(new Main()).start();
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kgduu

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值