Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- 정렬
- 다이나믹 프로그래밍
- 구현
- 백준
- 트리
- Unreal Engine 5
- 스택
- 브루트포스
- 그리디 알고리즘
- 알고리즘
- 그래프
- VR
- 누적 합
- 투 포인터
- 재귀
- 다익스트라
- 유니온 파인드
- 수학
- c++
- DFS
- 백트래킹
- BFS
- XR Interaction Toolkit
- 유니티
- 자료구조
- Team Fortress 2
- 문자열
- 시뮬레이션
- 우선순위 큐
- ue5
Archives
- Today
- Total
1일1알
백준 14426번 접두사 찾기 C++ 본문
https://www.acmicpc.net/problem/14426
14426번: 접두사 찾기
문자열 S의 접두사란 S의 가장 앞에서부터 부분 문자열을 의미한다. 예를 들어, S = "codeplus"의 접두사는 "code", "co", "codepl", "codeplus"가 있고, "plus", "s", "cude", "crud"는 접두사가 아니다. 총 N개의 문자
www.acmicpc.net
unordered_set 이용
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
int n, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
unordered_set<string> st;
cin >> n >> m;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
string prefix = "";
for (int j = 0; j < str.length(); j++) {
prefix += str[j];
st.insert(prefix);
}
}
int ans = 0;
for (int i = 0; i < m; i++) {
string str;
cin >> str;
auto it = st.find(str);
if (it != st.end()) ans++;
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 16469번 소년 점프 C++ (0) | 2022.10.27 |
---|---|
백준 3474번 교수가 된 현우 C++ (0) | 2022.10.26 |
백준 15724번 주지수 C++ (0) | 2022.10.24 |
백준 17129번 윌리암슨수액빨이딱따구리가 정보섬에 올라온 이유 C++ (0) | 2022.10.23 |
백준 12869번 뮤탈리스크 C++ (0) | 2022.10.22 |