title: "JadenCase 문자열 만들기" category: 프로그래머스[Level-2] tags: [C++, JavaScript, 프로그래머스] date: "2021-02-01" 문제 링크 JadenCase 문자열 만들기 C++ #include #include using namespace std; string solution(string s) { string answer = ""; answer+=toupper(s[0]); // 처음 대문자(공백이면 공백) for(int i=1; i { return val.replace(/[a-z]/, (v, i) => { if (i === 0) return v.toUpperCase(); else return v; }); }) .join(" "); return an..
title: "최대공약수와 최소공배수" category: 프로그래머스[Level-1] tags: [C++, JavaScript, 프로그래머스] date: "2021-01-20" 문제 링크 최대공약수와 최소공배수 C++ #include #include using namespace std; int func(int a, int b){ if(a % b == 0) return b; return func(b, a % b); // 나누어떨어질 때까지 재귀 } vector solution(int n, int m) { vector answer; answer.push_back(func(n, m)); // 최대공약수 answer.push_back(n*m/answer[0]); // 최소공배수 return answer; } J..
title: "콜라츠 추측" category: 프로그래머스[Level-1] tags: [C++, JavaScript, 프로그래머스] date: "2021-01-20" 문제 링크 콜라츠 추측 C++ #include #include #include using namespace std; int solution(int num) { int answer = 0; long numLong = num; // int 범위 초과 for(int i=0; i
title: "평균 구하기" category: 프로그래머스[Level-1] tags: [C++, JavaScript, 프로그래머스] date: "2021-01-20" 문제 링크 평균 구하기 C++ #include #include using namespace std; double solution(vector arr) { double answer = 0; for(auto e: arr){ answer += e; } answer /= arr.size(); return answer; } JavaScript function solution(arr) { var answer = 0; arr.forEach((value) => { answer += value; }); answer /= arr.length; return a..
title: "하샤드 수" category: 프로그래머스[Level-1] tags: [C++, JavaScript, 프로그래머스] date: "2021-01-20" 문제 링크 하샤드 수 C++ #include #include using namespace std; bool solution(int x) { bool answer = true; int sum = 0; string str = to_string(x); for(char c: str){ sum += (c - '0'); } answer = (x%sum==0) ? true : false; return answer; } JavaScript function solution(x) { var answer = true; let sum = 0; x.toString(..