본문 바로가기

Algorithm23

[프로그래머스] 42842번 카펫 C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42842?language=cpp 메모- sqrt()  https://blockdmask.tistory.com/307 [C언어/C++] pow, sqrt 함수에 대해서(루트함수, 제곱, 제곱근)안녕하세요. BlockDMask 입니다 오늘은 (저는) 자주 쓰지는 않지만 꼭 알아둬야하는 함수를 두개 묶어서 가지고왔습니다. 바로 pow, sqrt 함수인데요. 중학교때 제곱과 제곱근(루트) 배우셨죠? 그걸이blockdmask.tistory.com 풀이- yellow의 세로 길이를 i로 하는 for문. yellow를 i로 나누어 떨어지는 경우 i와 yellow/i가 노란색 부분의 세로, 가로 길이.. 2024. 11. 13.
[프로그래머스] 42839번 소수 찾기 C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42839 메모- 소수인지 판별할 때 에라토스테네스의 체 사용- stoi  https://velog.io/@haminggu/C-%EB%AC%B8%EC%9E%90%EC%97%B4-%EC%B2%98%EB%A6%AC-%ED%95%A8%EC%88%98-cstr-atoi-stoi-%ED%8A%B9%EC%A7%95%EA%B3%BC-%EC%82%AC%EC%9A%A9%EB%B2%95 [C++] 문자열 처리 함수 c_str(), atoi(), stoi() 특징과 사용법c_str() 함수는 C++의 std::string 클래스의 멤버 함수로, C++ 스타일의 문자열을 C 스타일의 문자열(const char.. 2024. 11. 13.
[프로그래머스] 42840번 모의고사 C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42840 맞힌 코드#include #include using namespace std;vector solution(vector answers) { vector answer; vector v1 = {1,2,3,4,5}; vector v2 = {2,1,2,3,2,4,2,5}; vector v3 = {3,3,1,1,2,2,4,4,5,5}; int one=0, two=0, three=0; for (int i=0; imax) max = arr[i]; } for (int i=0; i 2024. 11. 13.
[프로그래머스] 86491번 최소직사각형 C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/86491 맞힌 코드#include using namespace std;int solution(vector> sizes) { int w = 0; int h = 0; for (int i=0; iw) w = sizes[i][0]; if (sizes[i][1]>h) h = sizes[i][1]; } return w*h;} 2024. 11. 13.
[프로그래머스] 42747번 H-Index C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42747  메모  맞힌 코드#include using namespace std;int solution(vector citations) { int answer = 0; sort(citations.begin(), citations.end(), greater()); for (int i=0; i= i+1){ answer++; } } return answer;} 2024. 11. 13.
[프로그래머스] 42748번 K번째수 C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42748 메모- sort 문법 맞힌 코드#include using namespace std;vector solution(vector array, vector> commands) { vector answer; for (int l=0; l v; int i = commands[l][0]; int j = commands[l][1]; int k = commands[l][2]; for (int m=i-1; m 2024. 11. 12.
[프로그래머스] 43162번 네트워크 C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/43162 메모- 주어진 모든 컴퓨터들은 computers[i][i]의 값이 1임   -> 이걸 이용해서 방문한 컴퓨터에 대해서는 computers[i][i]의 값을 0으로 바꾸어 방문 표시하기- dfs로 컴퓨터 방문해서 연결되어 있는 j 컴퓨터들(computers[i][j]의 값이 1인 컴퓨터들)에 대해서 dfs 수행- dfs 내에 있는 computers[i][i]==0이면 return하는 조건문은 dfs가 중첩되어 수행되는 경우에 필요함 맞힌 코드#include using namespace std;void dfs(int i, vector> &computers){ if (compu.. 2024. 11. 11.
[프로그래머스] 1844번 게임 맵 최단거리 C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/1844 메모- bfs 방법으로 풀이- vector> maps의 n, m 값 구하는 코드는 다음과 같음  int n = maps.size();  int m = maps.[0].size();- maps의 값이 1 이하인 경우 방문하지 못한 것으로 판별해 -1 return 맞힌 코드#include using namespace std;int solution(vector > maps){ int answer = 0; int dx[] = {0, 0, -1, 1}; int dy[] = {-1, 1, 0, 0}; int n = maps.size(); int m = maps[0.. 2024. 11. 11.