[ 알고리즘 ]/Implementation

    [프로그래머스/C++] 숫자 문자열과 영단어

    [프로그래머스/C++] 숫자 문자열과 영단어

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/81301 🎖️난이도 Level 1 ✔️풀이 // sol1) map(dict), isdigit, substr 이용 #include #include #include #include #include using namespace std; int solution1(string s) { map m; m["zero"] = "0"; m["one"] = "1"; m["two"] = "2"; m["three"] = "3"; m["four"] = "4"; m["five"] = "5"; m["six"] = "6"; m["seven"] = "7"; m["eight"] = "8"; m["nine"] = "9"; int..

    [프로그래머스/C++] 소수 찾기

    [프로그래머스/C++] 소수 찾기

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/12921 🎖️난이도 Level 1 ✔️풀이 // 정답 #include #include #include #include using namespace std; int solution(int n) { int cnt = 0; //bool arr[1000001] = {true}; // 이렇게 하면 첫번째 값만 true로 초기화됨! (나머지는 false) //arr[0] = arr[1] = false; // 0과 1은 소수 x // 배열 초기화 (sol1) /* bool arr[1000001]; for(int i = 2; i 조금 더 느림 // 에라토스테네스의 체 => 배수들(소수가 아닌 애들)을 0으로..

    [프로그래머스/C++] 폰켓몬

    [프로그래머스/C++] 폰켓몬

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/1845 🎖️난이도 Level 1 ✔️풀이 // 정답 #include #include #include using namespace std; int solution(vector nums) { int N = nums.size(); set s(nums.begin(), nums.end()); return N / 2 > s.size() ? s.size() : N / 2; } // 오답 (시간초과) => 순열과 조합 다 구할 필요 X #include #include #include #include // next_permutation(순열), 조합 using namespace std; int solution..

    [프로그래머스/C++] 2016년

    [프로그래머스/C++] 2016년

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/12901 🎖️난이도 Level 1 ✔️풀이 #include #include #include using namespace std; string solution(int a, int b) { vector days = { 31,29,31,30,31,30,31,31,30,31,30,31 }; vector date = { "FRI", "SAT", "SUN", "MON", "TUE", "WED", "THU" }; /* int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31}; string date[7] = {"FRI", "SAT", "SUN", "MON", "TUE",..

    [프로그래머스] 교점에 별 만들기

    [프로그래머스] 교점에 별 만들기

    📌문제 https://school.programmers.co.kr/learn/courses/30/lessons/87377 🎖️난이도 Level 2 ✔️풀이 from itertools import combinations def solution(line): # 모든 교점 중 정수쌍 구하기 intersections = set() for comb in combinations(line, 2): a,b,e = comb[0] c,d,f = comb[1] if a*d == b*c : continue x = (b*f-e*d) / (a*d-b*c) y = (e*c-a*f) / (a*d-b*c) if x == int(x) and y == int(y): intersections.add((int(x), int(y))) # 여기..