#프로그래머스 #1단계 #C++ 59

프로그래머스 - 같은 숫자는 싫어 - C++

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

프로그래머스 - 직사각형 별찍기 - C++

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

프로그래머스 - 문자열 다루기 기본 - C++

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

프로그래머스 - 행렬의 덧셈 - C++

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

프로그래머스 - 부족한 금액 계산하기 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/82612 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr using namespace std; long long solution(int price, int money, int count) { long long answer = money; for(int i=1;i0) return 0; else return answer*-1; } 설명 이 문제는 놀이기구를 count번탈 때의 총 비용보다 money가 작은지 큰지를 비교해서 크면 0을 작으면 얼만큼 작은지를..

프로그래머스 - 하샤드 수 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/12947 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; bool solution(int x) { int n = 0; int ori = x; while(x>0) { n+=x%10; x/=10; } if(ori%n==0) return true; else return false; } 설명 주어진 x 가 하샤드 수인지를 구하는 문제이다. 하샤드 수란 모든 자릿수의 합으로 x가 나누어 떨어지..

프로그래머스 - 수박수박수박수박수박수? - C++

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

프로그래머스 - 콜라츠 추측 - C++

https://school.programmers.co.kr/learn/courses/30/lessons/12943 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr #include #include using namespace std; int solution(int num) { int answer = 0; long long a = num; while(true) { if(a==1)break; if(a%2==0)a/=2; else a=a*3+1; answer++; if(answer==500) return -1; } return answer; } 설명 이 문제는 n..

프로그래머스 - 가운데 글자 가져오기 - C++

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