Search

문자열4_문제09_상품취소

대분류
STEP09 문자열
문제 난이도
LV09
소분류
문자열4_문제

영상

문제

<script> /* [문제] member는 회원목록이다. 번호와 아이디가 기록되어있다. item은 쇼핑몰 판매상품이다. 상품이름과 가격이 기록되어있다. order는 오늘 주문 목록이다. 주문한 회원 아이디와 아이템 이름 그리고 주문개수가 기록되어있다. cancel은 주문취소 목록이다. 취소한 회원 아이디와 아이템 이름 그리고 주문개수가 기록되어있다. 오늘의 매출을 출력하시오. [정답] 7700 */ let member = "qwer1234,pythongood,testid"; let item = "사과,1100/바나나,2000/딸기,4300"; let order = "qwer1234,사과,3/phthongood,바나나,2/qwer1234,딸기,5/testid,사과,4"; let cancel = "qwer1234,딸기,5/phthongood,바나나,2"; </script>
Java
복사

해설

<script> /* [문제] member는 회원목록이다. 번호와 아이디가 기록되어있다. item은 쇼핑몰 판매상품이다. 상품이름과 가격이 기록되어있다. order는 오늘 주문 목록이다. 주문한 회원 아이디와 아이템 이름 그리고 주문개수가 기록되어있다. cancel은 주문취소 목록이다. 취소한 회원 아이디와 아이템 이름 그리고 주문개수가 기록되어있다. 오늘의 매출을 출력하시오. [정답] 7700 */ let member = "qwer1234,pythongood,testid"; let item = "사과,1100/바나나,2000/딸기,4300"; let order = "qwer1234,사과,3/phthongood,바나나,2/qwer1234,딸기,5/testid,사과,4"; let cancel = "qwer1234,딸기,5/phthongood,바나나,2"; let memberList = []; let itemList = []; let orderList = []; let cancelList = []; let token = member.split(","); for(let i=0; i<token.length; i++) { memberList.push(token[i]); } token = item.split("/"); for(let i=0; i<token.length; i++) { let unit = token[i].split(","); unit[1] = Number(unit[1]); itemList.push(unit); } token = order.split("/"); for(let i=0; i<token.length; i++) { let unit = token[i].split(","); unit[2] = Number(unit[2]); orderList.push(unit); } token = cancel.split("/"); for(let i=0; i<token.length; i++) { let unit = token[i].split(","); unit[2] = Number(unit[2]); cancelList.push(unit); } //------------------------------------------------------ let countList = [0, 0, 0]; for(let i=0; i<itemList.length; i++) { for(let j=0; j<orderList.length; j++) { if(itemList[i][0] == orderList[j][1]) { countList[i] += orderList[j][2]; } } for(let j=0; j<cancelList.length; j++) { if(itemList[i][0] == cancelList[j][1]) { countList[i] -= cancelList[j][2]; } } } let total = 0; for(let i=0; i<countList.length; i++) { total += countList[i] * itemList[i][1]; } document.write(total); </script>
Java
복사