영상
문제
<script>
/*
[문제]
memberList는 회원목록데이터이다.
number는 회원 번호이다.
id 는회원 아이디이다.
itemList은 쇼핑몰 판매 상품 데이터이다.
itemname은 상품이름이다.
price는 아이템 가격이다.
orderList는 오늘 주문 목록이다.
orderid는 주문한 회원 id 이다.
itemname는 주문한 상품이름이다.
count는 주문한 상품개수이다.
각 회원별 상품별 이름과 총가격을 구하시오.
단, 아무것도 주문하지 않은 회원은 구하지 않는다.
[정답]
{"id":"qwer1234","itemname":"사과","count":4,"total":4400}
{"id":"pythongood","itemname":"사과","count":2,"total":2200}
{"id":"pythongood","itemname":"딸기","count":6,"total":25800}
{"id":"testid","itemname":"바나나","count":8,"total":16000}
{"id":"cccddd","itemname":"사과","count":2,"total":2200}
{"id":"cccddd","itemname":"바나나","count":3,"total":6000}
*/
let memberList = [
{"number" : 1001, "id" : "qwer1234"},
{"number" : 1002, "id" : "pythongood"},
{"number" : 1003, "id" : "testid"},
{"number" : 1004, "id" : "aaabbb"},
{"number" : 1005, "id" : "cccddd"}
];
let itemList = [
{"itemname" : "사과", "price" : 1100},
{"itemname" : "바나나", "price" : 2000},
{"itemname" : "딸기", "price" : 4300}
];
let orderList = [
{"orderid" : "qwer1234", "itemname" : "사과", "count" : 3},
{"orderid" : "pythongood", "itemname" : "딸기", "count" : 6},
{"orderid" : "testid", "itemname" : "바나나", "count" : 1},
{"orderid" : "pythongood", "itemname" : "사과", "count" : 2},
{"orderid" : "testid", "itemname" : "바나나", "count" : 7},
{"orderid" : "qwer1234", "itemname" : "사과", "count" : 1},
{"orderid" : "cccddd", "itemname" : "바나나", "count" : 3},
{"orderid" : "cccddd", "itemname" : "사과", "count" : 2}
];
</script>
Java
복사
해설
<script>
/*
[문제]
memberList는 회원목록데이터이다.
number는 회원 번호이다.
id 는회원 아이디이다.
itemList은 쇼핑몰 판매 상품 데이터이다.
itemname은 상품이름이다.
price는 아이템 가격이다.
orderList는 오늘 주문 목록이다.
orderid는 주문한 회원 id 이다.
itemname는 주문한 상품이름이다.
count는 주문한 상품개수이다.
각 회원별 상품별 이름과 총가격을 구하시오.
단, 아무것도 주문하지 않은 회원은 구하지 않는다.
[정답]
{"id":"qwer1234","itemname":"사과","count":4,"total":4400}
{"id":"pythongood","itemname":"사과","count":2,"total":2200}
{"id":"pythongood","itemname":"딸기","count":6,"total":25800}
{"id":"testid","itemname":"바나나","count":8,"total":16000}
{"id":"cccddd","itemname":"사과","count":2,"total":2200}
{"id":"cccddd","itemname":"바나나","count":3,"total":6000}
*/
let memberList = [
{"number" : 1001, "id" : "qwer1234"},
{"number" : 1002, "id" : "pythongood"},
{"number" : 1003, "id" : "testid"},
{"number" : 1004, "id" : "aaabbb"},
{"number" : 1005, "id" : "cccddd"}
];
let itemList = [
{"itemname" : "사과", "price" : 1100},
{"itemname" : "바나나", "price" : 2000},
{"itemname" : "딸기", "price" : 4300}
];
let orderList = [
{"orderid" : "qwer1234", "itemname" : "사과", "count" : 3},
{"orderid" : "pythongood", "itemname" : "딸기", "count" : 6},
{"orderid" : "testid", "itemname" : "바나나", "count" : 1},
{"orderid" : "pythongood", "itemname" : "사과", "count" : 2},
{"orderid" : "testid", "itemname" : "바나나", "count" : 7},
{"orderid" : "qwer1234", "itemname" : "사과", "count" : 1},
{"orderid" : "cccddd", "itemname" : "바나나", "count" : 3},
{"orderid" : "cccddd", "itemname" : "사과", "count" : 2}
];
let resultList = [];
for(let i=0; i<memberList.length; i++) {
for(let j=0; j<itemList.length; j++) {
let total = 0;
for(let k=0; k<orderList.length; k++) {
if(memberList[i]["id"] == orderList[k]["orderid"]) {
if(itemList[j]["itemname"] == orderList[k]["itemname"]) {
total += orderList[k]["count"];
}
}
}
if(total > 0) {
let info = {};
info["id"] = memberList[i]["id"];
info["itemname"] = itemList[j]["itemname"];
info["count"] = total;
info["total"] = total * itemList[j]["price"];
document.write(JSON.stringify(info) + "<br>");
resultList.push(info);
}
}
}
</script>
Java
복사