MarkSon
-
백준 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 배열을 활용
-
C++ string 정리 (1)소프트웨어전공/C++ Programming 2021. 9. 22. 13:46
https://blockdmask.tistory.com/338 [C++] string 클래스, 문자열에 대해서 (총정리) 안녕하세요 BlockDMask 입니다. 오늘은 C++의 std::string 클래스(문자열)에 대해서 세세 하게 알아볼것 입니다. 예전 글을 보다가 제가 작성한 이 문서를 보게 되었는데요, 너무 내용이 빈약하다고 blockdmask.tistory.com 어떤 분께서 좋은 자료를 올려두어 이를 통해 공부했다. 내용이 적지 않아서 당장 필요한 것들 위주로 우선 정리! 1. string 선언 char*, char[] 과는 달리 문자열 끝에 '\0'이 들어있지 않다. Null문자가 뒤에 따로 없다는 것..! 2. string 클래스의 함수들 정리 - 양이 많아서 몇가지만 살펴보기로 했다. ..
-
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일때 즉 첫번째 배..