Buy List
Submit solution
Points:
40 (partial)
Time limit:
1.0s
Memory limit:
256M
Authors:
Problem types
Allowed languages
Java 19, Java 8
題目說明
請設計一類似購物清單的程式,讓使用者可以輸入要買的商品,存到HashMap,最後輸出整個HashMap
import java.util.*;
public class ContactInfo {
public static void main(String[] args) {
HashMap<String, Integer> buyList = new HashMap<>();
/*
補上缺少的程式碼
*/
// 印出購物清單
System.out.println(buyList);
}
}
輸入
先輸入要買的商品,當輸入為.
結束
注意,輸入的商品可能有重複
輸出
購物清單
測試資料 輸入
apple banana orange cheese yogurt banana orange .
測試資料 輸出
{banana=2, orange=2, apple=1, yogurt=1, cheese=1}
// HashMap無序,無需考慮輸出的排序問題
Comments
題解
應用題 // 參考試算表A268、試算表A270、筆記