본문 바로가기

전체 글135

[백준/BOJ] 2164번 카드2 C++ 문제 링크 : https://www.acmicpc.net/problem/2164 맞힌 코드#include using namespace std;int n;int main(void){ cin >> n; queue q; for (int i=0; i 2024. 11. 20.
[프로그래머스] 42577번 전화번호 목록 C++ 문제 링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42577 메모- 모든 전화번호 각각에 대해서 string 배열값 앞에서부터 비교? 더 작은 거 길이만큼 for문 돌려서 긴 거랑 비교해서 풀려고 했는데... 이렇게 되면 더 작은 모든 문자열에 대해서 for문을 돌려야 됨. 모든 문자열 개수-1 * 작은 문자열의 길이 만큼 for문 돌리면 시간 초과가 뜨겠지...- 해시 맵에 가능한 문자열들을 value 값이 1인 key로 넣어서 그 해시맵을 대상으로 문자열들을 돌리는 코드를 작성해야 됨  맞힌 코드#include using namespace std;bool solution(vector phone_book) { bool answer.. 2024. 11. 15.
[프로그래머스] 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.