Baekjoon 2605. 줄세우기 c++[Bronze II]
·
Baekjoon/Bronze
https://www.acmicpc.net/problem/2605#include #include #include using namespace std;int main() { int n; cin >> n; vector numbers(n); for (int i = 0; i > numbers[i]; } vector line; for (int i = 0; i ::iterator it=line.begin();it!=line.end();++it){ cout  * 연산자를 사용해 it이 가리키는 원소실제 포인터가 아닌 *연산자를 overloading해서 포인터처럼 동작하게 한 것입력 값을 넣고 reverse없이 그냥 출력을 해보면 1 3 5 2 4로 나올 것..
Baekjoon 1002. 터렛 c++[Silver III]
·
Baekjoon/Silver
위에 그림이 생각 났으면 쉽게 풀 수 있는 문제#include #include #include using namespace std;int main(){ int test_case; cin >> test_case; for(int i=0;i> x1 >> y1 >> r1 >> x2 >> y2 >> r2; int d=pow(x1-x2,2)+pow(y1-y2,2); int r_minus=pow(r1-r2,2); int r_plus=pow(r1+r2,2); if(d==0){ if(r_minus==0) cout
[LeetCode/CodeWars] - Two Sum [JS]
·
알고리즘(Algorithm)
난이도 LeetCode => easy CodeWars => 6kyu 1) 문제를 읽고 바로 떠올릴 수 있는 풀이 2개의 반복문으로 값들을 더하면서 target이 되는 값들의 index를 return해준다. function twoSum(numbers, target) { for (let i = 0; i < numbers.length-1; i++) { for (let j = i+1; j < numbers.length; j++) { if (numbers[i] + numbers[j] === target) return [i, j]; } } } 2)자바스크립트가 가지고 있는 indexOf를 사용해서도 풀이가 가능하다 function twoSum(numbers, target) { for (i = 0; i < numbe..
[CodeWars] Give me a Diamond [JS / 6kyu] 다이아 찍기
·
알고리즘(Algorithm)
다이아 찍기 최대한 for문을 하나만 쓰려고 고민했다 function diamond(n){ if(n===1) return '*\n' if(n
프로그래머스 - 영어 끝말잇기[JS]
·
알고리즘(Algorithm)
풀이 - player는 나머지 연산자를 사용해 n이하의 값으로 반복 1. 마지막글자, 앞글자 비교하기 2. 같은 글자 찾기 3. player가 n과 같아지면 차례++ function solution(n, words) { let first=words[0] let count=1 for (let i = 1; i j===words[i])!==i) return [player,count] first=words[i] if(player===n) count++ } return [0,0] }
undefined 방지하기
·
JavaScript
자바스크립트는 값이 할당되지 않은 변수에게는 undefined라는 값을 할당한다. 값이 할당되어 있기에 코드가 동작할 때도 있지만, undefined때문에 그 변수를 건드리려고 해도 건드리지 못한다. https://github.com/tc39/proposal-nullish-coalescing GitHub - tc39/proposal-nullish-coalescing: Nullish coalescing proposal x ?? y Nullish coalescing proposal x ?? y. Contribute to tc39/proposal-nullish-coalescing development by creating an account on GitHub. github.com 객체에서 이런 경우가 종종 발..
프로그래머스 - 숫자의 표현 [JS]
·
알고리즘(Algorithm)
풀이 연속된 자연수들의 합으로 자연수 n을 만들어라 완전탐색 -> 시간 초과 1,2,3... 이런식으로 더해나가다가 n이 되면 count++ 다음 숫자는 2부터 시작, 3부터 시작 ... 더해서 n이되면 count++, n (자기자신) count++ 간단하게 이중 for문으로 구현 function solution(n) { let count=0 for (let i = 1; i n이 15일때 연속된 자연수의 합 중 가장 큰 자연수(자기 자신 제외)의 조합은 7+8 즉, 최대 범위는 -> n/2 자기자신을 포함하기 때문에 count에 미리 1을 주고 풀었다 재귀와 합쳐서 만든 2번째 풀이 -> 통과 function solution(n) { let count=1 const helper=(num,sum)=>{ i..
프로그래머스 - 명예의 전당
·
알고리즘(Algorithm)
풀이 먼저, score를 한개씩 보내기 위해 forEach를 사용해 helper 함수에 전달 score.forEach((i)=>{ helper(i) }) 만약, fame(명예의 전당에 오른 점수)의 길이가 k보다 작을 경우 fame에 값을 push하고 최솟값을 구해서 결과값에 push if(fame.lengthmin){ fame.splice(fame.indexOf(min),1) fame.push(point) min=Math.min(...fame) res.push(min) } else if(point{ if(fame.lengthmin){ fame.splice(fame.indexOf(min),1) fame.push(point) min=Math.min(...fame) res.push(min) } else if..
프로그래머스 - 키패드 누르기 [JS]
·
알고리즘(Algorithm)
풀이 keypad를 배열로 만들면 반복문을 사용해야한다는 단점이 있기에 객체로 만들어서 각 손가락 위치에 해당하는 값들을 계산해 비교 -> finger function solution(numbers, hand) { let res=[] const keypad = { 1: [0, 0], 2: [0, 1], 3: [0, 2], 4: [1, 0], 5: [1, 1], 6: [1, 2], 7: [2, 0], 8: [2, 1], 9: [2, 2], '*': [3, 0], 0: [3, 1], '#': [3, 2] } let currentLeftFinger='*' let currentRightFinger='#' const helper=(lf,rf,num)=>{ const left=Math.abs(keypad[lf][0..
프로그래머스 - 크레인 인형뽑기 게임 [JS]
·
알고리즘(Algorithm)
풀이 function solution(board, moves) { let pickedDolls = []; let res=0 const checkDolls=(dolls)=>{ for (let i = 0; i { for (let i = 0; i < board.length; i++) { if (board[i][dollRow - 1] !== 0) { pickedDolls.push(board[i][dollRow - 1]); checkDolls(pickedDolls) board[i].spli..