Product Price Lookup


Submit solution

Points: 45 (partial)
Time limit: 1.0s
Memory limit: 64M

Authors:
Problem type

題目說明

請設計一個程式,使用 HashMap<String, Integer> 儲存商品名稱及其價格。使用者先輸入多筆商品資料,之後輸入一個商品名稱,查詢並輸出該商品的價格。

如果查無此商品,請輸出 "Product not found"

輸入

  • 第一行輸入一個整數 n,代表要輸入幾筆商品資料。

  • 接下來 n 行,每行包含一個商品名稱(不含空白)與其價格(整數),以空白分隔。

  • 最後一行輸入一個商品名稱,作為查詢用的名稱。

輸出

  • 若商品存在於資料中,請輸出該商品的價格(整數)。

  • 若商品不存在,請輸出 Product not found

範例輸入 #1

3
apple 30
banana 45
orange 50
banana

範例輸出 #1

45

範例輸入 #2

2
milk 60
bread 40
coffee

範例輸出 #2

Product not found

Comments

There are no comments at the moment.