[1] priority_queue
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
여기서 greater<...>는 “작은 값이 먼저 나오게 해줘” 라는 의미로 이 pq는 최소 힙(min-heap) 이 된다.
결과: pq.top()은 가장 작은 pair 가 됨
비교 과정
1. first 먼저 비교
2. first가 같으면 second 비교
예시)
(2, 5) vs (3, 1) → first 비교니까 (3, 1)이 더 큼
(2, 5) vs (2, 1) → first 같으니까 second 비교해서 (2, 5)가 더 큼
priority_queue<pair<int,int>> pq;
기본 비교자가 less<T>라서 큰 값이 먼저 나오는 최대 힙(max-heap) 이 된다.
결과: pq.top()은 가장 큰 pair 를 반환함
[2] Ascii Code
- 아스키코드: 숫자, 소문자, 대문자
char c = s[i];
if (c >= '0' && c <= '9') {
// 숫자 (아스키 48~57)
int num = c - '0'; // 숫자로 변환
}
else if (c >= 'a' && c <= 'z') {
// 소문자 (아스키 97~122)
}
else if (c >= 'A' && c <= 'Z') {
// 대문자 (아스키 65~90)
}
- cctype 라이브러리 사용
#include <cctype>
if (isdigit(c)) {
// 숫자
}
else if (isalpha(c)) {
// 알파벳
}
[3] s.substr(0,n): 인덱스 0부터 n개 문자를 자르기
s.substr(시작 인덱스, 길이);
string s = "aabbaccc";
s.substr(0, 1); // "a"
s.substr(0, 2); // "aa"
s.substr(0, 3); // "aab"
s.substr(0, 4); // "aabb"