프로그래머스

    [2] JadenCase 문자열 만들기

    #include #include using namespace std; string solution(string s) { string answer = ""; answer+=toupper(s[0]); for(int i=1;i

    [2] 최댓값과 최솟값

    #include #include #include using namespace std; string solution(string s) { vector v; string temp = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == ' ') { v.push_back(stoi(temp)); temp = ""; } else temp += s[i]; } v.push_back(stoi(temp)); sort(v.begin(), v.end()); return to_string(v.front()) + ' ' + to_string(v.back()); }

    [3] 등굣길

    #include #include #define SIZE 101 using namespace std; int solution(int m, int n, vector puddles) { int check[SIZE][SIZE]{0}, vis[SIZE][SIZE]{0}; for(int i=0;i

    [3] 단속 카메라

    #include #include #include using namespace std; int solution(vector routes) { int answer = 1; sort(routes.begin(), routes.end()); int tmp = routes[0][1]; for (auto a : routes) { if (tmp = a[1]) tmp = a[1]; } return answer; }

    [3] 베스트 앨범

    참고 사이트 : 알고리즘(C++) / 프로그래머스 level 3 : 베스트앨범 (tistory.com) #include #include #include #include #include #include #include using namespace std; using StringPair = pair; using IntPair = pair; // 내림차순 정렬 bool CmpStr(StringPair& a, StringPair& b) { return a.second > b.second; } bool CmpInt(IntPair& a, IntPair& b) { return (a.first == b.first) ? a.second b.first; } vector soluti..

    [3] 이중 우선순위 큐

    삭제 추가가 용이한 이중 연결 리스트를 사용했다. #include #include #include #include using namespace std; vector solution(vector operations) { vector answer; list bl, sl; for (const auto& item : operations) { string str = item; str.erase(remove(str.begin(), str.end(), ' '), str.end()); if (str[0] == 'I') { string tmpStr = ""; for (int i = 1; i < str.size(); i++) tmpStr += str[i]; bl.push_back(stoi(tmpStr)); bl.sort(..

    [3] 숫자 게임

    #include #include #include using namespace std; int solution(vector A, vector B) { int answer = 0; sort(A.begin(),A.end()); sort(B.begin(),B.end()); int idxA=A.size()-1,idxB=B.size()-1; while(idxA >= 0) { int valA=A[idxA],valB=B[idxB]; if(valB > valA) { answer++; idxB--; } idxA--; } return answer; }

    [3] 가장 먼 노드

    이 문제에는 함정이 존재한다 따라서 SIZE를 20001로 지정한다. #include #include #include #include using namespace std; #define SIZE 20001 vector vGraph[SIZE]; vector vCount(SIZE); bool vis[SIZE]; void DFS(int start) { queue q; q.push(start); vis[start] = true; while (!q.empty()) { auto front = q.front(); q.pop(); for (int i = 0; i < vGraph[front].size(); i++) { auto val = vGraph[front][i]; if (!vis[val]) { vis[val] = ..

    [3] 섬 연결하기

    #include #include #include using namespace std; vector vIsland(100); bool Cmp(vector a, vector b) { return a[2] < b[2]; } int FindParent(int idx) { if (vIsland[idx] != idx) vIsland[idx] = FindParent(vIsland[idx]); return vIsland[idx]; } int solution(int n, vector costs) { int answer = 0; sort(costs.begin(), costs.end(), Cmp); for (int i = 0; i < n; i++) vIsland[i] = i; for (int i = 0; i < costs...

    2016년 - Level1

    2016년 1월 1일은 금요일이므로 배열은 금요일부터 시작 day는 2016년 1~12월까지에 대한 일수다. 공식으로 간단하게 풀 수 있는 문제다. #include #include using namespace std; string solution(int a, int b) { string week[7]{"FRI","SAT","SUN","MON","TUE","WED","THU"}; int day[]{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int val=0; for(int i=0;i week[4] = "TUE" }