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
- 문자열
- 투 포인터
- 백준
- 트리
- 백트래킹
- BFS
- 재귀
- 알고리즘
- c++
- 유니온 파인드
- Team Fortress 2
- ue5
- 정렬
- 수학
- 브루트포스
- 구현
- 다이나믹 프로그래밍
- 자료구조
- Unreal Engine 5
- 우선순위 큐
- 그리디 알고리즘
- 유니티
- XR Interaction Toolkit
- 시뮬레이션
- 누적 합
- DFS
- VR
- 스택
- 그래프
- 다익스트라
Archives
- Today
- Total
1일1알
백준 14713번 앵무새 C++ 본문
https://www.acmicpc.net/problem/14713
14713번: 앵무새
자가용 비행기를 타고 세계 일주를 하던 pps789와 cseteram은 어느 날 엔진 고장으로 인해 이름 모를 섬에 불시착하게 된다. 그들은 이 섬을 탐험하는 도중 아주 신기한 사실을 알게 되었는데, 바로
www.acmicpc.net
단어들이 순서대로 맞춰졌는지와 모든 단어가 사용되었는지 있는지 확인해야한다.
#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;
vector<queue<string>> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
cin.ignore();
v = vector<queue<string>>(n);
string sentence;
for (int i = 0; i < n; i++) {
getline(cin, sentence);
int front = 0;
string tmp = "";
for (int j = 0; j <= sentence.length(); j++) {
if (sentence[j] != ' ' && j != sentence.length()) continue;
tmp = sentence.substr(front, j - front);
front = j + 1;
v[i].push(tmp);
}
}
getline(cin, sentence);
int front = 0;
string tmp = "";
queue<string> q;
for (int i = 0; i <= sentence.length(); i++) {
if (sentence[i] != ' ' && i != sentence.length()) continue;
tmp = sentence.substr(front, i - front);
front = i + 1;
q.push(tmp);
}
int cnt = 0;
while (!q.empty()) {
string curr = q.front();
q.pop();
bool ans = false;
for (int i = 0; i < n; i++) {
if (v[i].empty()) continue;
if (v[i].front() != curr) continue;
ans = true;
v[i].pop();
if (v[i].empty()) cnt++;
break;
}
if (ans == false) {
cout << "Impossible";
return 0;
}
}
if (cnt != n) cout << "Impossible";
else cout << "Possible";
}
'알고리즘' 카테고리의 다른 글
백준 20208번 진우의 민트초코우유 C++ (0) | 2023.03.01 |
---|---|
백준 11332번 시간초과 C++ (1) | 2023.02.28 |
백준 1972번 놀라운 문자열 C++ (0) | 2023.02.25 |
백준 18513번 샘터 C++ (0) | 2023.02.24 |
백준18429번 근손실 C++ (0) | 2023.02.23 |