본문 바로가기

분류 전체보기

(454)
[Level 1][C++] 소수의 합 #include #include #include using namespace std;long long solution(int N) { long long sum = 0; bool *arr = new bool[N + 1]; for (int i = 0; i
[Level 2][C++] 기능개발 #include #include using namespace std;vector solution(vector progresses, vector speeds) { vector answer; int days=1; //날짜 1일 부터 시작. int idx=0; //맨 앞에 프로젝트 부터 시작 while(true) { int count = 0; //이날 배부된 프로젝트 개수. while(progresses[idx]+days*speeds[idx]>=100) { idx++; //다음 프로젝트로 넘어감. 끝난 프로젝트가 다 배부될 때까지. ..
[Level 2][C++] 올바른 괄호 #include#includeusing namespace std;bool solution(string s){ char* arr = new char[s.length()+1]; strcpy(arr, s.c_str()); //문자열 문자 배열에 복사 int count=0; for(int i=0; i
[Level 2][C++] 다음 큰 숫자 #include ​using namespace std; ​int countOne(int number) //2진수로 바꿨을 때 1을 구하는 함수{ int count=0; while(number>0) { count = (number%2==1)? ++count: count; number /=2; } return count; } ​int solution(int n) { int nOne = countOne(n); int answer = n; while(true) { answer++; if(countOne(answer)==nOne) return answer;..
[Level 2][C++] 숫자의 표현 #include #include using namespace std;int solution(int n) { int answer = 0; for(int i=1; i
[Level 2][C++] 폰켓몬 #include #include using namespace std;int solution(vector nums){ set poketmons; for(int i=0; i=nums.size()/2) return nums.size()/2; else return poketmons.size();}
[Level 2][C++] 카펫 #include #include using namespace std;vector solution(int brown, int red) { vector result; for (int col = 3; col
[Level 2][C++] 최댓값과 최솟값 #include #include #include // streamstring의 헤더#include using namespace std;string solution(string s) { vector nums; stringstream ss(s); // 문자열을 stringstream에 집어넣음. string numString; while(ss>>numString) //공백 기준으로 쪼갠다. { nums.push_back(stoi(numString)); //문자열을 int로 변환해서 배열에 집어넣는다. } sort(nums.begin(), nums.end()); //오름차순으로 정렬 //int를 string으로 변환 strin..
[Level 2][C++] 최솟값 만들기 #include #include#include using namespace std;int solution(vector A, vector B){ sort(A.begin(), A.end()); sort(B.begin(), B.end(), greater()); int answer = 0; for(int i=0; i
[Level 2][C++] 행렬의 곱셈 #include #include using namespace std;vector> solution(vector> arr1, vector> arr2) { vector> answer(arr1.size()); for(int i=0; i i 첫번째 행렬의 행, j 첫번째 행렬의 열이자 두번째 행렬의 행, k 두번째 행렬의 열