본문 바로가기

전체 글

(105)
[프로그래머스]압축문자열 난이도: 하? #include #include #include using namespace std; vector solution(string msg) { vector answer; vector dict; //1번부터 시작하기 위해 더미값 삽입 dict.push_back(""); //A~Z 알파벳 삽입 for(int i = 0; i
[프로그래머스]방금그곡 문제를 풀면서 여러 조건을 추가했고, 정확성이 50 -> 70 -> 98 -> 100 순으로 향상했다. 정답을 맞추긴 했지만, 내 코드가 정답이라고 하긴 어려워 보인다. (기존 코드를 개선하기는 방법으로는 토큰화나 변환이 있다) #include #include #include #include using namespace std; vector store; string solution(string m, vector musicinfos) { string answer = "(None)"; int cur = 0; string str = ""; vector vec; vector answerList; //','를 기준으로 문자열 분리 for(int index = 0; index
[ 프로그래머스]다음 큰 숫자 처음에 이진수의 모든 가능한 경우를 구한 후 다음 큰 숫자를 구하려고 했다. 하지만 효율성 문제를 해결하지 못했고 다른 방법을 이용해야 했다. 풀이: 현재 숫자에서 1을 증가시키고 이진수에서의 1의 개수를 카운트 한다. 주어진 숫자의 1의 개수와 증가시킨 숫자의 1의 개수가 같다면 그 때의 값이 답이다. 아래는 틀린 답 #include #include #include using namespace std; vector store; void DFS(string str, int limit, int count, int subCount) { if (str.length() == limit || subCount > count) { if (count == subCount) { store.push_back(str); }..
[프로그래머스]단체사진 찍기 우선 모든 가능한 경우의 수를 구하기 위해 DFS를 사용했고 store 배열에 모든 경우의 수를 담았다. 그리고 나서 두 개의 큐(fQ, sQ)를 선언해 data 배열의 조건을 하나씩 확인하면서 빈 큐에 푸쉬했다. 반복하는 data의 인덱스마다 저장되어있는 큐에서 빈큐로 (fQ에서 sQ로 또는 sQ에서 fQ로)데이터를 필터링해 이동시킨다. 모든 data의 조건을 검사한 후 남아있는 경우의 수를 answer에 넣어준다. #include #include #include #include #include using namespace std; vector store; string kakaoCharacter; bool check[8]; void DFS(string str) { if(str.length() == 8)..
[SWEA]2814. 최장 경로 삽질.... 0 final) { final = count; lastX = x; } for(int idx = 1; idx >T; int N, M; for(test_case = 1; test_case > N >> M; for(int idx = 1; idx y >> x; check[y][x] = true; check[x][y] = true; } lastX = x; final = 1; if(N > 1) { ..
[BOJ]1874번: 스택 수열 #include #include #include int stack[1000000]; int main(void) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int len; std::cin >> len; std::vector val(len); for(int idx = 0; idx > val[idx]; } std::fill(stack, stack + 1000000, 0); int valPos = 0; int seq = 1; int max = 0; std::vector store; while(valPos
[BOJ]1181번: 단어 정렬 #include #include #include int aPos, bPos; bool compare(std::string a, std::string b) { if(a.length() != b.length()) { return a.length()
[LeetCode]#2 Add Two Numbers /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */#include class Solution {public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode newNode(0); ListNode *returnNode = &newNode; int sum = 0; int curTen = 0; while(l1 || l2 || curTen) { int val1 = l1 != NULL ? l1->val : 0; int val2 = l2 != NULL ? ..