본문 바로가기

전체 글245

[프로그래머스] 두 수의 연산값 비교하기(c++) https://school.programmers.co.kr/learn/courses/30/lessons/181938 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 답 #include using namespace std; int solution(int a, int b) { string a1=to_string(a); string b1=to_string(b); return max(stoi(a1+b1),2*a*b); } 이번 문제는 "더 크게 합치기"와 비슷한 유형의 문제이다. ​ 입력된 정수 a,b를 문자열로 바꾸어 저장한다. (to_string(_)사용) 문.. 2023. 12. 26.
[프로그래머스] 더 크게 합치기(c++) https://school.programmers.co.kr/learn/courses/30/lessons/181939 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 답 #include using namespace std; int solution(int a, int b) { int ans1=0,ans2=0; string a1=to_string(a); string b1=to_string(b); return max(stoi(a1+b1),stoi(b1+a1)); } ans1과 ans2를 만들었지만 사용하지 않았다. ​ 입력된 정수a,b를 문자열로 바꾸어 준다. (.. 2023. 12. 26.
[프로그래머스] 문자열 곱하기(c++) https://school.programmers.co.kr/learn/courses/30/lessons/181940 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 답 #include #include using namespace std; string solution(string my_string, int k) { string ans; for(int i=0;i 2023. 12. 26.
[프로그래머스] 홀수 vs 짝수(c++) https://school.programmers.co.kr/learn/courses/30/lessons/181887 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 답 #include using namespace std; int solution(vector num_list) { int ans1=0,ans2=0; for(int i=0;i 2023. 12. 26.
[프로그래머스] 문자열로 변환(c++) https://school.programmers.co.kr/learn/courses/30/lessons/181845?language=cpp 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 답 #include using namespace std; string solution(int n) { // return 값은 malloc 등 동적 할당을 사용해주세요. 할당 길이는 상황에 맞게 변경해주세요. return to_string(n); } 정수 n을 입력받고 숫자를 문자열로 바꿔어 주는 함수인 to_string을 사용했다. ​ 참고로 문자열을 숫자로 바꿀때는sto.. 2023. 12. 26.
[프로그래머스] n의 배수(c++) https://school.programmers.co.kr/learn/courses/30/lessons/181937 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 답 #include #include using namespace std; int solution(int num, int n) { int answer = 0; if(num%n==0){ answer=1; } else{ answer=0; } return answer; } num을 n으로 나누었을때 나머지가 0이라면 num은 n의 배수 이다. 끝 2023. 12. 26.