-
항해 99 5기 TIL_34항해 99 2022. 2. 13. 01:15
▶ Today I Learned
<알고리즘 스터디>
조이스틱
유형: 탐욕법
소요 시간: 1시간 25분
시간 내 해결 여부: 미해결
https://programmers.co.kr/learn/courses/30/lessons/42860
/* 조이스틱을 좌우로 움직이는 경우의 수를 따져 경우가 더 적은 쪽을 택하기 (근데 이때 좌우의 경우는 문자열 내 A가 포함되어있는 경우만 따지면됨 아닌 경우는 다 똑같음), 그 다음 상하 움직이는 경우의 수를 따져 경우가 더 적은 쪽을 택하기 맨 처음엔 A로만 이루어져 있습니다. 첫 시작은 항상 첫번째 */ let name = "EERAEAA" let leftRight = 0 //AJEARAO 이거에서 거꾸로 시작하는 건 마치 // AOARAEJ와 같다 // 그렇다면 // 문자열 첫번째 문자를 제외하고 잘라낸 다음 그것을 배열로 쪼개 역순으로 뒤집고 이를 다시 합쳐주어 원래 문자에 더하자. let reversedName = name.substring(0,1) + name.substring(1).split('').reverse().join('') console.log(reversedName) //문자열 내 A가 포함되어 있는가? 그리고 문자중 하나라도 A가 아닌게 있는가? console.log(name.includes('A')); if(name.includes('A')) { // 좌우 경우의 수 따지기 console.log(name.split('')) // "JERAOEN" 인 경우를 고려해보면 A가 중간에 있을 때 나눈 배열의 길이는 같지만 실제로 첫번째에서 마지막문자로 갈때의 횟수 1이 더해지므로 둘중 어떤 선택지가 나을지 비교할 때 [첫번째 배열 길이]와 [두번째 배열 길이 +1]을 비교해주어 더 큰쪽이 있다면 그쪽을 택해야 함 console.log(reversedName.split('')) console.log(name.split('').lastIndexOf('A')) console.log(reversedName.split('').lastIndexOf('A'))// 인덱스가 더 큰쪽이 적게 감 -> 더 마지막 부분에 A가 있기 때문? // 하지만 "EEEAEAR"로 하게 되면 인덱스가 각각 5,4 이지만 횟수는 똑같아 fail // name이나 reversedName의 마지막 글자중 하나라도 A인 경우에는 위의 식이 성립, 아니라면 인덱스 번호가 어떻든 간에 결과는 같음 if(name[name.length-1] === 'A' || reversedName[reversedName.length-1] === 'A') { if(name.split('').lastIndexOf('A') > reversedName.split('').lastIndexOf('A')) { reversedName.length == 7 - 1 // EERAEAA처럼 마지막에 A가 몰려있는 경우?는 어떻게 값을 반환하지? // 뒤집으면 AAEAREE E의 인덱스는 2 // console.log(name.split('').reverse().reduce((a, b, curIndex) => {if(a === 'A' && b === a) {} else {return curIndex}})) // reduce 구문이 안 멈춘다.. let i = 0 while (i < name.length) { if(name.split('').reverse()[i] === 'A' && name.split('').reverse()[i] === name.split('').reverse()[i+1]) { } else { console.log('정답', i+1) reversedName.length - 1 - (i + 1) return } i++ }; // EERAEAA에서 E의 인덱스는 4 } } };
그래도 이번엔 잘 풀리는 느낌이다!
좌우만 얼른 마무리 짓는다면 상하는 쉬울 것 같다!
내일 마무리 지어야지 :)
▶ 느낀 점
현재 새로운 프로젝트 백엔드 중 댓글 부분 구현에 있다. 지난번 했던 부분들이 많아서 우선은 코드를 들고와 비슷한 구조로 구현 중이다.
늦어도 월요일까진 모두 구현해보아야겠다.
또 알고리즘도 마무리하고, CS 강의도 좀 복습하고, 새로운 CS 지식도 찾고... 할 것이 참 많다 허허..
그래도 같이 하는 이들이 있기에 오늘도 즐거운 하루였다! 내일도 열공해야지!
화이팅팅! :3
▶ 공부 시 참고 링크들
이번 주차에 많이들 git conflict로 고생하시던데 나도 혹시몰라 한 번 해결법을 검색해보았다.
이분의 설명이 도움이 될 것 같아 여기 적어본다.
https://velog.io/@devmin/git-conflict-solution-basic
https://expressjs.com/en/resources/middleware/cors.html
https://hunjang.tistory.com/19
https://developer.mozilla.org/ko/docs/Web/HTTP/Basics_of_HTTP/MIME_types
https://studyingych.tistory.com/43
'항해 99' 카테고리의 다른 글
항해 99 5기 WIL_5 (0) 2022.02.13 항해 99 5기 TIL_35 (0) 2022.02.13 항해 99 5기 TIL_33 (0) 2022.02.12 항해 99 5기 TIL_32 (0) 2022.02.11 항해 99 5기 TIL_31 (0) 2022.02.10