일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
- 딥러닝
- 조지아텍
- 위니펙
- 머신러닝
- Plotting
- 선형대수
- 방송통신대학교
- 캐나다 영주권
- EOI
- 주정부이민
- Deep learning
- LAA
- cpp
- leetcode
- 프로그래머스
- 알고리즘
- LV1
- 코딩테스트
- zeros
- 컴퓨터과학과
- MATLAB
- omscs
- C++
- mpnp
- machine learning
- 개발자
- 매트랩
- 기본
- 온라인석사
- 방통대
- Today
- Total
목록C++ (16)
Byte by Byte

핵심 : 진법 변환 연습. 배운 것 : vector를 썼다면, to_string과 y[i]-0을 생략할 수 있었겠다. #include #include #include using namespace std; string convertToTernary(int& x){ string s = ""; while(x!=0){ s += to_string(x % 3); x /= 3; } return s; } int convertToDecimal(string y){ int decimal = 0; for(int i =0; i < y.size(); i++) decimal += (y[i]-'0')*pow(3,y.size()-(i+1)); return decimal; } int solution(int n) { return conv..

배운 점 : 1) pair의 second value로 sorting하고 싶을 때는, sort parameter에 cmp함수(외부에 작성)를 추가. 2) pair를 대입하는 STL : vector.emplace_back( i , value) 주의할점은 i는 iterator성격의 값만 넣어야 함. (링크 참고) https://www.geeksforgeeks.org/vector-emplace-function-in-c-stl/ 3) 0으로 나누면 오류남. 항상 체크할 것. #include #include #include #include using namespace std; bool cmp(const pair& a, const pair& b) { if (a.second == b.second) return a.fi..

정렬하고, 달라지는 지점을 하나씩 더하면, 내가 고를 수 있는 방법의 가지수가 된다. 내가 고를 수 있는 수와 같으면 return. #include #include using namespace std; int solution(vector nums) { int answer = 1; sort(nums.begin(),nums.end()); for(int i =0; i < nums.size()-1; i++){ if(answer == (nums.size()/2)) return answer; if(nums[i]!=nums[i+1]) answer++; } return answer; } unordered set을 왜 생각못했을까. 아래는 unordered set을 활용한 다른 사람의 풀이. 1. 중복을 허용하지 않는다..

여기서는 배울 점이 크게 2가지가 있다. 1) unordered_map에 데이터를 넣는법(stirng,int pair한정)과, 2) 콜론(:)과 auto를 활용한 for문 작성법. 1)unordered_map에 데이터를 넣는법 vector container 쓸때는 push_back해서 뒤에서부터 차례로 넣었는데, map은 (string, int) pair일 경우, x[key]++; 하면 그냥 넣어진다. int의 경우 값을 지정하지 않으면 default로 0이 저장되어 잇나보다. 2)콜론(:)과 auto를 활용한 for문 작성법 ' : ' 내가 반복자로 쓸 데이터타입과 변수명을 지정하고, 그 반복자를 적용할 집합?만 지정해주면 된다. string 변수명 : 적용할 집합 for( string name : p..

#include #include using namespace std; string solution(vector table, vector languages, vector preference) { string answer = ""; vectortemp; int baseScore = 6; int intermSum = 0; int highScore = 0; for (int i = 0; i < table.size(); i++) { string word = ""; for (int p = 0; p < table[i].size(); p++) { if (table[i][p] != ' ') { word += table[i][p]; if (p == table[i].size() - 1) temp.push_back(word);..

#include #include using namespace std; int solution(vector board, vector moves) { int answer = 0; vector container; int temp =0; for(int m = 0; m

ㅇㅇㅇㅇ ㅇㅌㅌㅇ ㅇㅇㅇㅇ ㅇㅇㅇㅇㅇㅇ ㅇㅌㅌㅌㅌㅇ ㅇㅌㅌㅌㅌㅇ ㅇㅌㅌㅌㅌㅇ ㅇㅇㅇㅇㅇㅇ ㅇ와 ㅌ의 개수가 주어질때, ㅇ와 ㅌ전체로 이루어진 사각형에 대해, 가로와 세로의 값을 구하라. ㅇ= brown ㅌ = yellow #include #include using namespace std; vector solution(int brown, int yellow) { vector answer; for (int i =1; i

주어진 n 에 대하여 아래 조건이 성립하는 가지수를 도출. if n ==15 더하는 수는 자연수이며, 연속이어야함. 15 = 1 + 2 + 3 + 4 + 5 15 = 4 + 5 + 6 15 = 7 + 8 15 = 15 4가지. #include #include using namespace std; int solution(int n) { int answer = 0; int i = 1; while(i < n) { int sum = 0; int j = i; while(sum < n) { sum += j; j++; if(sum == n) answer++; } i++; } answer++; return answer; }