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
- 투 포인터
- DFS
- 다익스트라
- c++
- Team Fortress 2
- 백트래킹
- VR
- 유니온 파인드
- 유니티
- 백준
- 재귀
- 다이나믹 프로그래밍
- 수학
- XR Interaction Toolkit
- 시뮬레이션
- 브루트포스
- ue5
- 스택
- 구현
- 누적 합
- 문자열
- 자료구조
- Unreal Engine 5
- 그래프
- BFS
- 정렬
- 알고리즘
- 우선순위 큐
- 트리
- 그리디 알고리즘
Archives
- Today
- Total
1일1알
백준 1283번 단축키 지정 C++ 본문
getline으로 입력을 받고 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 <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
set<char> st;
bool IsExsist(char ch) {
auto it = st.find(tolower(ch));
if (it == st.end()) return false;
return true;
}
void PrintAns(string str, int idx = -1) {
for (int i = 0; i < str.length(); i++) {
if (i == idx) {
cout << '[' << str[i] << ']';
}
else cout << str[i];
}
cout << "\n";
}
void InsertAnsPrint(string str, int idx) {
st.insert(tolower(str[idx]));
PrintAns(str, idx);
}
bool Step1(string str) {
bool ret = false;
if (!IsExsist(str[0])) {
InsertAnsPrint(str, 0);
return true;
}
for (int i = 1; i < str.length(); i++) {
if (str[i] == ' ') {
if (i + 1 >= str.length()) return false;
if (IsExsist(str[i + 1])) continue;
InsertAnsPrint(str, i + 1);
return true;
}
}
return false;
}
bool Step2(string str) {
for (int i = 0; i < str.length(); i++) {
if (IsExsist(str[i])) continue;
if (str[i] == ' ') continue;
InsertAnsPrint(str, i);
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
string str;
cin >> n;
cin.ignore(99999, '\n');
for (int i = 0; i < n; i++) {
getline(cin, str);
if (Step1(str)) continue;
if (Step2(str)) continue;
cout << str << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 1331번 나이트 투어 C++ (0) | 2022.04.22 |
---|---|
백준 1292번 쉽게 푸는 문제 C++ (0) | 2022.04.21 |
백준 1270번 전쟁-땅따먹기 C++ (0) | 2022.04.19 |
백준 1251번 단어 나누기 C++ (0) | 2022.04.18 |
백준 1244번 스위치 켜고 끄기 C++ (0) | 2022.04.17 |