소프트웨어전공/알고리즘 문제풀이
-
C++ 모두의 약수 ( 제한시간 1초 )소프트웨어전공/알고리즘 문제풀이 2021. 9. 21. 20:46
문제는 https://markson.tistory.com/4 C++ 모두의 약수 일단 문제를 풀기 전에 종이에 나름 구현을 해보았다. 이중 for문을 이용하여 개수를 ++하는 방식으로 풀면 쉽겠다고 했는데 이상하리 엉뚱한 값이 나와서 해설을 보니.. 각 숫자의 약수의 개수이 markson.tistory.com 위의 풀이로는 시간제한을 통과하지 못하므로.. 문제는 오래 고민해도 이걸 떠올리기 쉽지 않다는 거.. 발상하는 과정을 따라 익히는 수 밖에 없다 -> 일일이 약수를 찾는게 아니라 배수의 관점에서 생각해 볼것.. "어떻게 하면 불필요한 연산을 제외하고 원하는 결과값을 얻을 수 있는가?" 특별한 발상이 아니라, 결국 위 질문으로부터 시작해서 이것저것 시도해 보는 태도가 필요하다.
-
C++ 모두의 약수소프트웨어전공/알고리즘 문제풀이 2021. 9. 21. 20:23
문제 출처 https://www.inflearn.com/course/%EC%95%8C%EA%B3%A0%EB%A6%AC%EC%A6%98/ it 취업을 위한 알고리즘 문제풀이 (with C/C++) : 코딩테스트 대비 - 인프런 | 강의 알고리즘과 자료구조를 이용해 문제해결력을 기르는게 주 목적입니다., 문제를 풀면서 자료구조와 알고리즘 기초·중급 개념을 확실히 잡고 다양한 문제를 통해 어떤 문제도 해결할 수 있는 문 www.inflearn.com 일단 문제를 풀기 전에 종이에 나름 구현을 해보았다. 이중 for문을 이용하여 개수를 ++하는 방식으로 풀면 쉽겠다고 했는데 이상하리 엉뚱한 값이 나와서 해설을 보니.. 각 숫자의 약수의 개수이기 때문에 개수를 i 마다 초기화 시켜줘야 한다.. "문제를 토씨 하나..
-
백준 11721번 _ C++ 열 개씩 끊어 출력하기소프트웨어전공/알고리즘 문제풀이 2021. 9. 21. 14:37
코드 풀기전 생각 11720번과 유사하게 짤 수 있을 듯 10번째 마다 개행을 하면 풀 수 있지 않을까? 10번째를 구분하려면 count++를 이용해서 하면 될거 같다. count가 10의 배수이면 개행 처리 결국 구글링 행.. 1. C언어 스타일 풀이 _ while문 활용 while로 입력받는 조건 설정 _ 이렇게도 쓸 수 있다 아직 while(), 특히 ()안에서 활용할 수 있는게 많은데 전혀 모른다.. 2. C++ with string 으로 푸는 방법. 구글링을 통해 찾아보면 가장 많이 나오는 방법이다. 포인트는 반복문 속의 조건문인데, index가 0부터 시작하므로 i % 10 == 9 로 해줘야 한다. 나의 경우 초기에 코드를 짤 때, i % 10 == 0으로 짰더니, i가 0일때 즉 첫번째 배..
-
백준 11720번 _ C++ 입출력소프트웨어전공/알고리즘 문제풀이 2021. 9. 21. 13:48
문제를 보고 우선 배열을 떠올렸다. 숫자가 공백없이 쓰여있고, 배열의 각 인덱스에 숫자를 차례대로 넣은 다음 배열의 요소를 모두 더해서 출력하면 될것이라 생각 그러나, 배열로는 결국 구현하지 못했다..! 구글링으로 여러 코드를 참조했는데, 풀이 방법은 다양했다. 1. 아스키 코드를 활용해서 푸는 법 입출력 문제에서 계속 헤매는 이유가 cin을 잘 몰라서 그렇다고 생각한다 아스키 코드를 써서 풀어도 되겠다는 생각은 했었지만, char에 N번만큼 값을 하나하나 담는다는것? 아직 이해가 완벽하게 안된다. -> char에는 단 하나의 문자만 담기니까, 12345라는 입력에는 1/2/3/4/5 이렇게 공간이 할당될 것이다. 2. 배열을 활용해서 푸는 법 내가 처음 문제를 풀때 떠올린 방법과 유사하다.