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
- 다이나믹 프로그래밍
- c++
- XR Interaction Toolkit
- 백준
- 트리
- 구현
- 재귀
- ue5
- 다익스트라
- Unreal Engine 5
- 백트래킹
- 유니티
- 수학
- 그래프
- DFS
- 자료구조
- 알고리즘
- BFS
- 브루트포스
- 스택
- 문자열
- 우선순위 큐
- 누적 합
- 유니온 파인드
- Team Fortress 2
- 시뮬레이션
- 그리디 알고리즘
- VR
- 투 포인터
- 정렬
Archives
- Today
- Total
1일1알
백준 5052번 전화번호 목록 C++ 본문
우선 처음에 입력받은 전화번호들을 전부 set에 넣고 전화번호를 앞에서부터 하나씩 탐색하면서 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 main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
bool ans = true;
int n;
cin >> n;
set<string> st;
vector<string> strs;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
strs.push_back(str);
st.insert(str);
}
for (int i = 0; i < n; i++) {
string tmp = "";
for (int j = 0; j < strs[i].length() - 1; j++) {
tmp += strs[i][j];
if (st.find(tmp) != st.end()) {
ans = false;
break;
}
}
if (ans == false) break;
}
if (ans) cout << "YES";
else cout << "NO";
cout << "\n";
}
}
'알고리즘' 카테고리의 다른 글
백준 4485번 녹색 옷 입은 애가 젤다지? C++ (0) | 2022.08.16 |
---|---|
백준 13913번 숨바꼭질 4 C++ (0) | 2022.08.15 |
백준 14402번 가장 긴 증가하는 부분 수열 4 C++ (0) | 2022.08.13 |
백준 1339번 단어 수학 C++ (0) | 2022.08.12 |
백준 1261번 알고스팟 C++ (0) | 2022.08.11 |