프로그래머스(Programmers)
-
Level 1> 문자열 내 p와 y의 개수프로그래머스(Programmers) 2018. 8. 8. 15:07
https://programmers.co.kr/learn/courses/30/lessons/12916 1. 문제 2. 알고리즘키워드 - 구현, 문자열 3. 코드 123456789101112131415161718192021222324252627282930#include #include #include #include using namespace std; bool solution(string s){ bool answer = true; const int size = s.size(); int count_p = 0; int count_y = 0; transform(s.begin(), s.end(), s.begin(), ::tolower); for(int i=0; i
-
Level 1 > 나누어 떨어지는 숫자 배열프로그래머스(Programmers) 2018. 8. 8. 15:05
https://programmers.co.kr/learn/courses/30/lessons/12910 1. 문제 2. 알고리즘키워드 - 구현, 배열 3. 코드 12345678910111213141516171819202122#include #include #include using namespace std; vector solution(vector arr, int divisor) { vector answer; sort(arr.begin(), arr.end()); const int size = arr.size(); for(int i=0; i
-
프로그래머스 > Level 1 > 가운데 글자 가져오기프로그래머스(Programmers) 2018. 8. 8. 14:58
https://programmers.co.kr/learn/courses/30/lessons/12903?language=cpp 1. 문제 2. 알고리즘키워드 - 문자열 3. 코드 12345678910111213141516171819#include #include using namespace std; string solution(string s) { string answer = ""; const int size = s.size(); int cand = size / 2; if(size % 2 == 0) { answer.push_back(s[cand-1]); answer.push_back(s[cand]); } else { answer.push_back(s[cand]); } return answer;}Colore..
-
프로그래머스 사용자 제작 문제 > 소수의 합프로그래머스(Programmers) 2018. 7. 11. 10:22
https://programmers.co.kr/learn/courses/30/lessons/14406 1. 문제소수 판별 알고리즘 소수의 합을 구하는 문제 2. 알고리즘키워드 - 소수 판별법, 에라토스테네스의 체 3. 코드 1234567891011121314151617181920212223242526272829303132#include #include using namespace std; long long solution(int N) { long long answer = 0; vector arr(N+1, 0); for (int i = 2; i
-
프로그래머스 Level 3 > 가장 긴 펠린드롬프로그래머스(Programmers) 2018. 7. 3. 20:40
https://programmers.co.kr/learn/courses/30/lessons/12904 1. 문제앞뒤를 뒤집어도 똑같은 문자열을 팰린드롬(palindrome)이라고 합니다.문자열 s가 주어질 때, s의 부분문자열(Substring)중 가장 긴 팰린드롬의 길이를 return 하는 solution 함수를 완성해 주세요. 예를들면, 문자열 s가 abcdcba이면 7을 return하고 abacde이면 3을 return합니다. 제한사항문자열 s의 길이 : 2500 이하의 자연수문자열 s는 알파벳 소문자로만 구성 2. 알고리즘키워드 - 문자열, 성준대리님은 풀었어요 3. 코드 123456789101112131415161718192021222324252627#include #include #includ..
-
프로그래머스 Level 3 > 2 x n 타일링프로그래머스(Programmers) 2018. 7. 3. 20:30
https://programmers.co.kr/learn/courses/30/lessons/12900 1. 문제전형적인 타일링 갯수 세는 문제 2. 알고리즘키워드 - 다이나믹 프로그래밍프로그래머스 알고리즘 문제 개선으로 인하여 효율성 및 테스트 조건 추가 됨 3. 코드 123456789101112131415161718#include #include using namespace std; int solution(int n) { int answer = 0; int dp[600001] = {0,}; dp[1] = 1; dp[2] = 2; for(int i=3; i
-
프로그래머스 Level1 > 시저 암호프로그래머스(Programmers) 2018. 7. 3. 20:21
https://programmers.co.kr/learn/courses/30/lessons/12926 1. 문제어떤 문장의 각 알파벳을 일정한 거리만큼 밀어서 다른 알파벳으로 바꾸는 암호화 방식을 시저 암호라고 합니다. 예를 들어 AB는 1만큼 밀면 BC가 되고, 3만큼 밀면 DE가 됩니다. z는 1만큼 밀면 a가 됩니다. 문자열 s와 거리 n을 입력받아 s를 n만큼 민 암호문을 만드는 함수, solution을 완성해 보세요. 제한 조건공백은 아무리 밀어도 공백입니다.s는 알파벳 소문자, 대문자, 공백으로만 이루어져 있습니다.s의 길이는 8000이하입니다.n은 1 이상, 25이하인 자연수입니다.입출력 예snresultAB1BCz1a 2. 알고리즘키워드 - 문자열 3. 코드 12345678910111213..