<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    emu in blogjava

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      171 隨筆 :: 103 文章 :: 1052 評論 :: 2 Trackbacks


    Problem Statement
    ????
    A company stores sales data in a single, cumbersome file. Each line of the file represents one sale and is formatted as:
        CLIENT_ID CNT_1 PRODUCT_1 CNT_2 PRODUCT_2 ...
    This indicates that CNT_1 units of PRODUCT_1 were sold to the client whose id is CLIENT_ID, and CNT_2 units of PRODUCT_2 and so on. You have been tasked with figuring out how many units of a particular product have been sold over time to a particular client. You will be given a String[] sales, a String, client, and a String, product. You are to return an int representing how many units of product were sold to client in sales.
    Definition
    ????
    Class:
    SalesFigures
    Method:
    getCount
    Parameters:
    String[], String, String
    Returns:
    int
    Method signature:
    int getCount(String[] sales, String client, String product)
    (be sure your method is public)
    ????

    Constraints
    -
    sales will contain between 1 and 50 elements, inclusive.
    -
    Each element of sales will be formatted as described in the problem statement, with at least 1 product and at most 50 characters.
    -
    CLIENT_ID and each PRODUCT_* will contain between 1 and 10 uppercase letters ('A'-'Z'), inclusive.
    -
    Each CNT_* will represent an integer between 1 and 999, inclusive, with no leading zeros.
    -
    client will contain between 1 and 10 uppercase letters ('A'-'Z'), inclusive.
    -
    product will contain between 1 and 10 uppercase letters ('A'-'Z'), inclusive.
    Examples
    0)

    ????
    {"BOB 1 SHOE",
     "JOHN 2 SHOE",
     "BOB 3 SHOE 1 HORSE"}
    "BOB"
    "SHOE"
    Returns: 4

    1)

    ????
    {"MEG 1 TV 1 VCR 10 DVD 3 DVD",
     "HARRY 2 TV 6 DVD",
     "MEG 11 DVD",
     "MEG 2 TV",
     "HARRY 101 DVD"}
    "MEG"
    "DVD"
    Returns: 24
    Note that "DVD" occurs twice in the first element.
    2)

    ????
    {"GEORGE 999 PETS"}
    "BOB"
    "SHOE"
    Returns: 0

    This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.

    posted on 2005-08-23 15:04 emu 閱讀(913) 評論(1)  編輯  收藏 所屬分類: google編程大賽模擬題及入圍賽真題

    評論

    # emu的解法 2005-08-23 15:11 emu

    import java.util.*;
    public class SalesFigures {
       
        public static void main(String[] args)
        {
            String[] sales =   {"GEORGE 999 PETS"};
            // CLIENT_ID CNT_1 PRODUCT_1 CNT_2 PRODUCT_2 ...
            String client = "BOB";
            String product = "SHOE";
            System.out.println(new SalesFigures().getCount(sales,client,product));

        }

        public int getCount(String[] sales, String client, String product){
            HashMap salesHsmp = new HashMap();
            for (int i=0;i<sales.length;i++){
                String[] saleDetail = sales[i].split(" ");
                String clientName = saleDetail[0];
                if (!salesHsmp.containsKey(clientName)) salesHsmp.put(clientName,new HashMap());
                HashMap clientHsmp = (HashMap)salesHsmp.get(clientName);
                for (int j=1;j<saleDetail.length;j+=2){
                    int unit = Integer.parseInt(saleDetail[j],10);
                    String tmpProduct = saleDetail[j+1];
                    if (clientHsmp.containsKey(tmpProduct)){
                        Integer productUnit = (Integer)clientHsmp.get(tmpProduct);
                        unit += productUnit.intValue();
                    }
                    clientHsmp.put(tmpProduct,new Integer(unit));
                }
            }
            HashMap clientHsmp = (HashMap)salesHsmp.get(client);
            if (clientHsmp == null) return 0;
            Integer unitInteger = (Integer)clientHsmp.get(product);
            return unitInteger==null?0:unitInteger.intValue();
        }

       
    }
      回復(fù)  更多評論
      

    主站蜘蛛池模板: 久久精品成人免费国产片小草| 国产亚洲人成无码网在线观看 | 亚洲 小说区 图片区 都市| 免费国产污网站在线观看15| 一级毛片不卡免费看老司机| 亚洲国产精品嫩草影院| 亚洲卡一卡2卡三卡4麻豆| 图图资源网亚洲综合网站| 亚洲熟妇丰满多毛XXXX| 亚洲人成网站色在线入口| 国产hs免费高清在线观看| 24小时日本在线www免费的| 2020因为爱你带字幕免费观看全集 | 日韩毛片在线免费观看| 亚洲成AV人片高潮喷水| 亚洲一区AV无码少妇电影| 亚洲另类春色校园小说| 亚洲免费电影网站| 亚洲系列中文字幕| 亚洲精品午夜久久久伊人| 亚洲视频在线不卡| 亚洲精品一卡2卡3卡三卡四卡| 亚洲一本综合久久| 亚洲AV永久无码精品成人| 国产亚洲一区二区三区在线| 亚洲熟妇无码八AV在线播放| 亚洲综合熟女久久久30p| 91麻豆精品国产自产在线观看亚洲| 亚洲精品国产电影| 久久亚洲中文字幕精品一区| 伊人亚洲综合青草青草久热| 91麻豆精品国产自产在线观看亚洲| 国产亚洲大尺度无码无码专线 | 51午夜精品免费视频| 成人精品综合免费视频| 国产精品高清免费网站| 免费看一区二区三区四区| 美女在线视频观看影院免费天天看| 无码国产精品一区二区免费式芒果| 99ee6热久久免费精品6| 久久国内免费视频|