본문 바로가기

datastructure

(24)
[BOJ] 1302번 베스트셀러 (C++) https://www.acmicpc.net/problem/1302 1302번: 베스트셀러 첫째 줄에 오늘 하루 동안 팔린 책의 개수 N이 주어진다. 이 값은 1,000보다 작거나 같은 자연수이다. 둘째부터 N개의 줄에 책의 제목이 입력으로 들어온다. 책의 제목의 길이는 50보다 작거나 같고 www.acmicpc.net #include #include using namespace std; int main() { int n, max = 0; string str, result; map m; cin >> n; for(int i = 0; i > str; if(m.find(str) != m.end()){ m[str]++; } else{ m[str] = 1; } } for(auto it ..
[BOJ] 11723번 집합 (C++) https://www.acmicpc.net/problem/11723 11723번: 집합 첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다. www.acmicpc.net #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int m; cin >> m; set s; set tmp; for(int i = 1; i > str; if(str == "add"){ cin >> k; s.insert(k); } else if(str == "remove"){ cin >> k; s...
[BOJ] 1620번 나는야 포켓몬 마스터 이다솜 (C++) https://www.acmicpc.net/problem/1620 1620번: 나는야 포켓몬 마스터 이다솜 첫째 줄에는 도감에 수록되어 있는 포켓몬의 개수 N이랑 내가 맞춰야 하는 문제의 개수 M이 주어져. N과 M은 1보다 크거나 같고, 100,000보다 작거나 같은 자연수인데, 자연수가 뭔지는 알지? 모르면 www.acmicpc.net #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; map m1; map m2; string s; for(int i = 1; i > s; m1.insert(make_pair(i, s)); m..
[BOJ] 1764번 듣보잡 (C++) https://www.acmicpc.net/problem/1764 1764번: 듣보잡 첫째 줄에 듣도 못한 사람의 수 N, 보도 못한 사람의 수 M이 주어진다. 이어서 둘째 줄부터 N개의 줄에 걸쳐 듣도 못한 사람의 이름과, N+2째 줄부터 보도 못한 사람의 이름이 순서대로 주어진다. www.acmicpc.net #include #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector v; vector t; string s, k; for(int i = 0; i > s; v.push_back(..
[BOJ] 2075번 N번째 큰 수 (C++) https://www.acmicpc.net/problem/2075 2075번: N번째 큰 수 첫째 줄에 N(1 ≤ N ≤ 1,500)이 주어진다. 다음 N개의 줄에는 각 줄마다 N개의 수가 주어진다. 표에 적힌 수는 -10억보다 크거나 같고, 10억보다 작거나 같은 정수이다. www.acmicpc.net #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); priority_queue pq; int n, k; cin >> n; for(int i = 0; i > k; pq.push(-k); if(pq.size() ..
[BOJ] 7662번 이중 우선순위 큐 (C++) https://www.acmicpc.net/problem/7662 7662번: 이중 우선순위 큐 입력 데이터는 표준입력을 사용한다. 입력은 T개의 테스트 데이터로 구성된다. 입력의 첫 번째 줄에는 입력 데이터의 수를 나타내는 정수 T가 주어진다. 각 테스트 데이터의 첫째 줄에는 Q에 적 www.acmicpc.net #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, k, num; char c; cin >> n; for(int i = 0; i > k; for(int j = 0; j > c; if(..
[BOJ] 10816번 숫자 카드 2 (C++) https://www.acmicpc.net/problem/10816 10816번: 숫자 카드 2 첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10, www.acmicpc.net #include #include #include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); int n, m, k; cin >> n; vector v; for(int i = 0; i > k; v.push_back(k); } sort(v.beg..
[BOJ] 11899번 괄호 끼워넣기 (C++) https://www.acmicpc.net/problem/11899 11899번: 괄호 끼워넣기 첫 번째 줄에 S를 올바른 괄호열으로 만들기 위해 앞과 뒤에 붙여야 할 괄호의 최소 개수를 출력합니다. 불가능한 경우는 주어지지 않습니다. www.acmicpc.net #include #include #include using namespace std; int main() { stack s; stack t; string str; cin >> str; for(int i = 0; i < str.length(); i++){ char c = str[i]; if(c == '('){ s.push(str[i]); } else { if(!s.empty()) s.pop(); else t.push(str[i]); } } cou..