영상
문제
<script>
/*
[문제]
userList는 회원들의 정보이다.
userno 는 회원번호이다.
username 은 회원이름이다.
pointList는 회원들의 점수이다.
userno 는 회원번호이다.
point는 포인트 점수이다.
포인트 점수가 가장높은 회원의 점수와 이름을 구하시오.
[정답]
5 김철수
*/
let userList = [
{"userno" : 1001 , "username" : "김철수"},
{"userno" : 1002 , "username" : "이만수"},
{"userno" : 1003 , "username" : "이영희"}
];
let pointList = [
{"userno" : 1001 , "point" : 1},
{"userno" : 1002 , "point" : 3},
{"userno" : 1001 , "point" : 4},
{"userno" : 1003 , "point" : 2},
{"userno" : 1003 , "point" : 1}
];
</script>
Java
복사
해설
<script>
/*
[문제]
userList는 회원들의 정보이다.
userno 는 회원번호이다.
username 은 회원이름이다.
pointList는 회원들의 점수이다.
userno 는 회원번호이다.
point는 포인트 점수이다.
포인트 점수가 가장높은 회원의 점수와 이름을 구하시오.
[정답]
5 김철수
*/
let userList = [
{"userno" : 1001 , "username" : "김철수"},
{"userno" : 1002 , "username" : "이만수"},
{"userno" : 1003 , "username" : "이영희"}
];
let pointList = [
{"userno" : 1001 , "point" : 1},
{"userno" : 1002 , "point" : 3},
{"userno" : 1001 , "point" : 4},
{"userno" : 1003 , "point" : 2},
{"userno" : 1003 , "point" : 1}
];
let maxPoint = 0;
let maxIndex = 0;
for(let i=0; i<userList.length; i++) {
let total = 0;
for(let j=0; j<pointList.length; j++) {
if(userList[i]["userno"] == pointList[j]["userno"]) {
total += pointList[j]["point"];
}
}
if(maxPoint < total) {
maxPoint = total;
maxIndex = i;
}
}
document.write(maxPoint + " " + userList[maxIndex]["username"]);
</script>
Java
복사