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

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

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

    emu in blogjava

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      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 閱讀(924) 評論(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();
        }

       
    }
      回復  更多評論
      

    主站蜘蛛池模板: 天天天欲色欲色WWW免费| 69免费视频大片| 亚洲日本va午夜中文字幕久久| 亚洲夂夂婷婷色拍WW47| 好吊妞视频免费视频| 亚洲综合av一区二区三区不卡| 黄瓜视频影院在线观看免费| 亚洲一级片在线观看| 无人在线观看免费高清视频 | 国产V亚洲V天堂A无码| 亚洲阿v天堂在线2017免费| 亚洲精品国产高清不卡在线| 一本到卡二卡三卡免费高| 亚洲无线码一区二区三区| 久久免费精品视频| 亚洲精品美女久久久久9999| 99爱在线精品免费观看| 亚洲日韩精品A∨片无码加勒比| 日本人护士免费xxxx视频| 九一在线完整视频免费观看| 国产精品亚洲片在线观看不卡 | 在线观看成人免费视频不卡| 亚洲视频在线观看2018| 日韩中文无码有码免费视频 | 亚洲 欧洲 视频 伦小说| 国产成人aaa在线视频免费观看| 高清免费久久午夜精品| 亚洲AV无码成人网站久久精品大 | 免费毛片在线视频| 一区二区三区免费视频观看| 国产亚洲精品a在线无码| 国产在线jyzzjyzz免费麻豆| 18禁亚洲深夜福利人口| 久久综合亚洲色HEZYO国产| 特级精品毛片免费观看| 亚洲欧美乱色情图片| 亚洲综合色婷婷七月丁香| 国产精品视频免费| 大片免费观看92在线视频线视频| 久久亚洲精品无码AV红樱桃| 国产高清在线免费视频|