전체 글 203

프로그래머스 - 특이한 정렬 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120880 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include #include using namespace std; int Num; bool compare(const int& a,const int& b) { if(abs(Num-a)

프로그래머스 - 다음에 올 숫자 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120924 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; int solution(vector common) { int answer = 0; bool ch=false; int d; if(common[1]-common[0]==common[2]-common[1]) { ch=false; d=common[1]-common[0]; } else { ch=true; d=common[1]/commo..

프로그래머스 - 최빈값 구하기 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120812#qna 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include #include using namespace std; int solution(vector array) { int answer = 0; map m; if (array.size() == 1) return array[0]; for (int i = 0; i < array.size(); i++) { if (m.find(array[i]) != m.en..

프로그래머스 - 종이 자르기 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120922 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; int solution(int M, int N) { int answer = 0; return (N-1)*M + M-1; } 설명 M * N 의 종이를 1*1 로 전부 자르기 위해서 몇번의 가위질이 필요한지를 구하는 문제이다. 1. 가로 즉 M번 가위질을 해서 1 * N 의 종이를 M개 만든다. 2. 그리고 1 * N 의 종이를..

프로그래머스 - 문자열 밀기 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120921 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; int solution(string A, string B) { int answer = 0; for(answer=0;;answer++) { if(answer>A.length())return -1; if(A==B) break; char c = A[A.length()-1]; for(int j=A.length()-1;j>=1;j--)..

프로그래머스 - 캐릭터의 좌표 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120861 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; vector solution(vector keyinput, vector board) { vector answer; answer.push_back(0);answer.push_back(0); int minR = -board[0]/2; int maxR = board[0]/2; int minC = -board[1]/2; int max..

프로그래머스 - 모스부호(1) - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120838 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; string solution(string letter) { string answer = ""; string arr[26] = { ".-","-...","-.-.","-..",".","..-.","--.","....","..",".---","-.-",".-..","--","-.","---",".--.","--.-",".-.","..

프로그래머스 - 진료순서 정하기 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120835 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; vector solution(vector emergency) { vector answer; int arr[101]={0,}; for(int i=0;i

Visual Studio - LNK2001 에러

위 처럼 LNK2001 에러가 발생하는 이유는 링크과정에서의 문제가 발생하기 때문이다. 여러 이유가 있다. 1. 헤더파일에 함수선언을 했지만 cpp파일에서 함수정의를 하지 않는 경우다. 2. static변수를 클래스 내부에 선언했는데 클래스 외부에서 정의하지 않은 경우다. 내 코드의 경우 2번 문제였다. GameManager.h class GameManager { private: GameManager() { chracter = nullptr; } static GameManager* _instance; //CharacterType chType; Character* chracter; GameManager 클래스에 _instance 변수를 static으로 선언했다. 그런데 cpp파일에서 정의하지 않아서 오류가..

C++ 2023.09.02

프로그래머스 - 소인수분해 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/120852 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include #include using namespace std; vector solution(int n) { vector answer; bool arr[10001]={0,}; int num = n; while(true) { bool ch=false; for(int i=2;i