본문 바로가기

코딩테스트_백준풀이54

큐 #10845 c++ 풀이 https://www.acmicpc.net/problem/10845 10845번: 큐 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 저번에 풀었던 스택에서 4-5줄 정도 바꾸니까 풀렸습니다. 역시 헤더파일에서 queue를 포함시켜주었습니다. #include #include #include #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NUL.. 2023. 10. 13.
스택 #10828 c++ 풀이 https://www.acmicpc.net/problem/10828 10828번: 스택 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 스택구현 기본문제인것 같습니다. 뭔가 생각할것 없이 그대로 구현하시면 됩니다. c++의 좋은점은 #include 처럼 자료구조가 미리 헤더파일에 다 정의되어있는 것입니다. c로 일일이 구현하지 않아도 되어 좋습니다. #include #include #include #include #include #include #include using namespace std; int main.. 2023. 10. 13.
요세푸스 문제 0 #11866 c++ 풀이 https://www.acmicpc.net/problem/11866 11866번: 요세푸스 문제 0 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000) www.acmicpc.net 봤을때 가장 먼저 떠오른 생각은, pop - push - pop - push - (pop) 의 반복일 것 같은데 하는 직관이 들었다. 결과는 정답. 출력형식이 조금 번거로워서 vector에 담아서 처리했습니다. #include #include #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int N.. 2023. 10. 12.
나이순 정렬 #10814 c++ 풀이 algorithm 함수인 sort 함수의 3번째 인자인 비교함수를 넘겨주는 방식으로 풀었다. 구조체를 만들어서 vector에 담아 정렬하는 방법이다. #include #include #include #include #include #include using namespace std; typedef struct IDC { int age; string name; int idx; //들어온순서 }; bool comp1(IDC a, IDC b) { if (a.age != b.age) return a.age < b.age; else return a.idx < b.idx; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n.. 2023. 10. 12.