-
[1283] 단축키 지정BOJ 2022. 5. 2. 02:04
https://www.acmicpc.net/problem/1283
1283번: 단축키 지정
첫째 줄에 옵션의 개수 N(1 ≤ N ≤ 30)이 주어진다. 둘째 줄부터 N+1번째 줄까지 각 줄에 옵션을 나타내는 문자열이 입력되는데 하나의 옵션은 5개 이하의 단어로 표현되며, 각 단어 역시 10개 이하
www.acmicpc.net
공백을 단축키로 지정하지 않도록 주의할 필요가 있다.
set에 대문자와 소문자를 항상 같이 넣어줌으로 "대소문자를 구분하지 않음" 을 구현할 수 있다.
#include <bits/stdc++.h>using namespace std;#ifdef ONLINE_JUDGEconstexpr bool local = false;#elseconstexpr bool local = true;#endifusing ll = long long;using pi = pair<ll, ll>;int n;set<int> st;vector<string> v;int main(void) {if (!local) ios_base::sync_with_stdio(0), cin.tie(0);cin >> n;int i, j;cin.ignore();for (i = 0; i < n; i++) {string s;getline(cin, s);int S = s.length();for (j = 0; j < S; j++) {if (j == 0 or s[j - 1] == ' ') {char x = s[j];if (x == ' ') continue;if (st.count(x) == 0) {st.insert((x | 32));st.insert((x & ~32));
s.insert(s.begin() + j, '[');s.insert(s.begin() + j + 2, ']');goto nxt_tc;}}}for (j = 0; j < S; j++) {char x = s[j];if (x == ' ') continue;if (st.count(x) == 0) {st.insert((x | 32));st.insert((x & ~32));
s.insert(s.begin() + j, '[');s.insert(s.begin() + j + 2, ']');goto nxt_tc;}}
nxt_tc:cout << s << '\n';}return 0;}
'BOJ' 카테고리의 다른 글
[14607] 피자 (Large) (0) 2022.05.13 [2312] 수 복원하기 (0) 2022.05.02 [24445] 알고리즘 수업 - 너비 우선 탐색 2 (0) 2022.05.02 [15967] 에바쿰 (0) 2022.05.02 [13900] 순서쌍의 곱의 합 (0) 2022.04.27