File tree Expand file tree Collapse file tree 4 files changed +82
-0
lines changed Expand file tree Collapse file tree 4 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
1
+ # 문제36 : 구구단 출력하기
2
+
3
+ 1~ 9까지의 숫자 중 하나를 입력하면 그 단의 구구단 결과를 한 줄에 출력하는 프로그램을 작성하세요.
4
+
5
+ ``` jsx
6
+ ** 입출력**
7
+
8
+ 입력 : 2
9
+ 출력 : 2 4 6 8 10 12 14 16 18
10
+ ```
Original file line number Diff line number Diff line change
1
+ /*
2
+ # 문제36 : 구구단 출력하기
3
+
4
+ 1~9까지의 숫자 중 하나를 입력하면 그 단의 구구단 결과를 한 줄에 출력하는 프로그램을 작성하세요.
5
+
6
+ ```jsx
7
+ **입출력**
8
+
9
+ 입력 : 2
10
+ 출력 : 2 4 6 8 10 12 14 16 18
11
+ ```
12
+ */
13
+
14
+ // 첫번째 풀이
15
+ // const times = prompt("1~9까지의 숫자 중 하나를 입력해주세요");
16
+ // function timesTable(times) {
17
+ // const arr = [];
18
+ // for (let i = 1; i <= 9; i++) {
19
+ // arr.push(times * i);
20
+ // }
21
+ // const answer = arr.join(" ");
22
+ // console.log(answer);
23
+ // }
24
+ // timesTable(times);
25
+
26
+ const num = prompt ( "1 ~ 9까지의 숫자 중 하나를 입력하세요." ) ;
27
+ let result = "" ;
28
+
29
+ for ( let i = 1 ; i <= 9 ; i ++ ) {
30
+ result += i * num + " " ;
31
+ }
32
+ //문자열로 더해주는게 더 심플하고 좋은 것 같다
33
+ console . log ( result ) ;
Original file line number Diff line number Diff line change
1
+ # 문제37 : 반장 선거
2
+
3
+ 새 학기를 맞아 호준이네 반은 반장 선거를 하기로 했습니다. 그런데 표를 하나씩 개표하는 과정이 너무 번거롭게 느껴진 당신은 ** 학생들이 뽑은 후보들을 입력받으면 뽑힌 학생의 이름과 받은 표 수를 출력하는 프로그램** 을 작성하기로 하였습니다.
4
+
5
+ ``` jsx
6
+ ** 입력**
7
+ 원범 원범 혜원 혜원 혜원 혜원 유진 유진
8
+
9
+ ** 출력**
10
+ 혜원(이)가 총 4 표로 반장이 되었습니다.
11
+ ```
Original file line number Diff line number Diff line change
1
+ /*
2
+ # 문제37 : 반장 선거
3
+
4
+ 새 학기를 맞아 호준이네 반은 반장 선거를 하기로 했습니다. 그런데 표를 하나씩 개표하는 과정이 너무 번거롭게 느껴진 당신은 **학생들이 뽑은 후보들을 입력받으면 뽑힌 학생의 이름과 받은 표 수를 출력하는 프로그램**을 작성하기로 하였습니다.
5
+
6
+ ```jsx
7
+ **입력**
8
+ 원범 원범 혜원 혜원 혜원 혜원 유진 유진
9
+
10
+ **출력**
11
+ 혜원(이)가 총 4표로 반장이 되었습니다.
12
+ ```
13
+ */
14
+
15
+ const students = prompt ( "학생들이 뽑은 후보들" ) . trim ( ) ;
16
+ function voting ( students ) {
17
+ const candidate = new Set ( students . split ( " " ) ) ;
18
+ const result = { } ;
19
+ candidate . forEach ( ( name ) => ( result [ name ] = students . split ( name ) . length - 1 ) ) ;
20
+ const maxNum = Math . max ( ...Object . values ( result ) ) ;
21
+
22
+ for ( let key in result ) {
23
+ if ( result [ key ] === maxNum ) {
24
+ return `${ key } 님이 ${ maxNum } 표로 선발되었습니다` ;
25
+ }
26
+ }
27
+ }
28
+ voting ( students ) ;
You can’t perform that action at this time.
0 commit comments