소프트웨어전공/알고리즘 문제풀이
-
프로그래머스 완주하지못한선수 [C++] feat.다양한 풀이방법소프트웨어전공/알고리즘 문제풀이 2021. 10. 6. 21:20
https://programmers.co.kr/learn/courses/30/lessons/42576 코딩테스트 연습 - 완주하지 못한 선수 수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수 programmers.co.kr [문제 접근] 두 개의 벡터 스트링 배열이 주어지고, 이 둘을 비교한다. 참가자 중에 동명이인이 있다는 조건이 있지만, 완주하지 못한 선수는 단 한명이기 때문에 어려운 요구사항은 아니었다. 반복문을 돌며 두 배열을 비교하고 같은것만 참가자 배열에서 삭제해주면 결국 단 하나의 요소만 남을 것이다. [C++ _ 중첩 반복문] [새로 알게된 것] ..
-
백준 1008번 : A/B [C++]소프트웨어전공/알고리즘 문제풀이 2021. 9. 28. 20:52
https://st-lab.tistory.com/212 [백준] 1008번 : A/B - [C++] www.acmicpc.net/problem/1008 1008번: A/B 두 정수 A와 B를 입력받은 다음, A/B를 출력하는 프로그램을 작성하시오. www.acmicpc.net 문제 알고리즘 [접근 방법] 이 문제는 '부동 소수점'에 대한 이해를 필요로.. st-lab.tistory.com 해당 블로그가 설명이 잘 되어있어 참고했다. 컴퓨터는 비트로 수를 표현한다. 음수는 2의보수로 표현가능함을 전공 기초를 통해 이미 배웠다. 그러나 소수는 과연 어떻게 표시야 하는지? 1/3은 0.33333......... 무한한 소수이다. 정확하게는 표현할 수 없다. 결국 근사치를 표현하는것이 최선이며 정확한 값에 조금..
-
프로그래머스 폰켓몬 _ [C++]소프트웨어전공/알고리즘 문제풀이 2021. 9. 28. 18:51
https://programmers.co.kr/learn/courses/30/lessons/1845 코딩테스트 연습 - 폰켓몬 당신은 폰켓몬을 잡기 위한 오랜 여행 끝에, 홍 박사님의 연구실에 도착했습니다. 홍 박사님은 당신에게 자신의 연구실에 있는 총 N 마리의 폰켓몬 중에서 N/2마리를 가져가도 좋다고 했습니다. programmers.co.kr 오늘 알고리즘 수업시간 퀴즈로 출제 되었다. 구현은 못했는데, 손코딩으로 어떻게 풀어야 되겠다 정도는 생각해낼 수 있었다. 여러가지 풀이가 있는데 일단 수업때 해설과 가장 유사한 코드부터 찾아보았다.
-
C++ 숫자의 총 개수소프트웨어전공/알고리즘 문제풀이 2021. 9. 26. 22:49
https://www.inflearn.com/course/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98 it 취업을 위한 알고리즘 문제풀이 (with C/C++) : 코딩테스트 대비 - 인프런 | 강의 알고리즘과 자료구조를 이용해 문제해결력을 기르는게 주 목적입니다., 문제를 풀면서 자료구조와 알고리즘 기초·중급 개념을 확실히 잡고 다양한 문제를 통해 어떤 문제도 해결할 수 있는 문 www.inflearn.com 문제는 쉽게 이해했는데, 코드로 구현을 못했다. 이번 문제는 코드가 아주 짧고, 풀이도 이해가 잘 갔는데.. 오래 붙들고 있어도 이걸 생각해 낼 수 있었을까? 하는 의구심이 든다 1 ~ 99999까지 조건문을 덕지덕지 붙여서 count를 하는 방식도 떠올려 보았으나 출제의도도..
-
백준 1152번 단어의 개수 _ [C++]소프트웨어전공/알고리즘 문제풀이 2021. 9. 25. 23:03
공백을 포함한 문자열을 입력받기 위해서는 getline() 함수가 필요하다. cin은 공백, 줄바꿈, 태그를 무시하고 데이터를 받기 때문이다. 처음에 cin으로 그것도 char배열을 선언해서 코드를 짜기 시작했는데 전혀 동작하지 않았다. 그리고 추가 조건인 공백으로 시작하거나 끝나는 경우에 대해 어떻게 처리할지 감이 오지 않아서 다른 사람들의 풀이를 찾아보았다. 답안 코드 마지막에 공백이 오는 경우는 고려하지 않기로 해서 애초에 for문이 string의 크기보다 1 작게 들어오게 했다. 첫 시작이 공백인 경우에는 앞선 for문에서 더해진 1을 다시 빼주게끔 조건문을 추가했다.
-
백준 1110번 더하기 사이클 [C++]소프트웨어전공/알고리즘 문제풀이 2021. 9. 24. 19:17
1. 풀이 전 전략 십의자리와 일의자리수를 구하기 위해 입력된 값 N에 대해 10으로 몫과 나머지 연산을 통해서 해결하고자 했다. 15분정도 구현을 시도하다가 아는것만으로 풀지 못할꺼 같아서 구글링을 시도했다. https://st-lab.tistory.com/260 [백준] 1110번 : 더하기 사이클 - [C++] https://www.acmicpc.net/problem/1110 1110번: 더하기 사이클 0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자 st-lab.tistory.com 풀이는 위 블로그의 글을 참고했다. 내가 몰랐던것들 1. int N을 그냥 선언하는게 아니라 init이라는 변수에 ..
-
백준 1924번 _ 2007년 x월 y일은 무슨 요일? [C++]소프트웨어전공/알고리즘 문제풀이 2021. 9. 23. 18:28
[풀이 시도] 정말 쉬워보였는데, 막상 풀려니 결국 못풀었다.. 문제에 있는 참고 정보에 따라 조건문을 나누는 식으로 31일, 30일 ,28일 이렇게 풀어내려고 했는데 그게 아니였음. 구글링으로 다양한 풀이들을 직접 따라해보면서 모르는 구현들을 줍줍하자.. 구글에 c++ 1924로 검색해서 1페이지에 뜨는것 코드들을 순서대로 참고했다. 1. switch & case 조건문 활용 32줄 이하는 생략. 코드가 다소 길지만, 요일을 나누는게 직관적으로 보여서 따라 구현해보았다. 2. string 배열을 활용