Algorithm 110

[백준 9613] C++ - GCD 최대공약수 구하기

처음에 int sum으로 했더니 틀렸다.⭐입력으로 주어지는 수가 1,000,000이하로 int형말고 long long으로 해야한다.//백준 9613 - GCD 합#include #include using namespace std;// 최대공약수 구하기int gcd(int a, int b){ if(b == 0) return a; return gcd(b, a%b);}int main(){ int t; scanf("%d", &t); // 테스트 케이스 개수 입력 while(t--){ int n; scanf("%d", &n); vector arr; int num; for(int i = 0; i

Algorithm/Baekjoon 2024.07.22

🟡[백준 2581] C++ - 소수 구하기

[C++] vector container 정리 및 사용법안녕하세요. BlockDMask 입니다.오늘은 C++ STL의 sequence container 중에 정말 자주 쓰는 vector에 대해서 알아보겠습니다. 1) vector container 란?2) vector의 사용 3) vector의 생성자와 연산자4-1) vector의 멤버 함수blockdmask.tistory.com 🟡틀린 코드 >> 원인 못찾음//백준 2581 - 소수#include #include #include #include //accumulate 함수 사용using namespace std;int main(){ int m, n; scanf("%d", &m); scanf("%d", &n); // m이상 n이하의 자연수 ..

Algorithm/Baekjoon 2024.07.22

[백준 1966] C++ - 우선순위 큐, pair

운체에서 배운 cpu 스케줄링 같다.우선순위가 주어진 큐!⭐C++에는 아래와 같이 우선순위 큐를 사용할 수 있다. 가장 큰 값이 top#include priority_queueint> pq; // 우선순위 큐//백준 1966 - 프린터 큐#include #include using namespace std;int main(){ int t; scanf("%d", &t); // 테스트 개수 입력 while(t--){ int cnt = 0; // 문서 개수 n, 몇 번째로 인쇄되었는지 궁금한 문제가 현재 큐에서 몇 번째에 놓여 있는지 m int n, m, p; // 우선순위 p scanf("%d %d", &n, &m); queue> q; priority_queue p..

Algorithm/Baekjoon 2024.07.22
728x90