1283 - 단축키 지정
2025. 2. 26. 13:08ㆍPS/백준
문제
https://www.acmicpc.net/problem/1283
느낀점
문자열 기본 구현 문제, 구현 문제는 차근차근 접근하자
풀이
#include <iostream>
#include <set>
#include <string>
#include <vector>
#include <cctype>
using namespace std;
int main()
{
int N;
cin >> N;
cin.ignore();
vector<string> arr(N);
set<char> abbr;
vector<string> words;
for (int i = 0; i < N; i++)
{
bool flag = false;
words.clear();
string in;
getline(cin, in);
string temp = "";
for (auto &c : in)
{
if (c == ' ')
{
words.push_back(temp);
temp = "";
continue;
}
temp += c;
}
words.push_back(temp);
string out = "";
for (size_t i = 0; i < words.size(); i++)
{
string word = words[i];
for (size_t j = 0; j < word.size(); j++)
{
if (j == 0 && abbr.find(toupper(word[j])) == abbr.end() && !flag)
{
abbr.insert(toupper(word[j]));
out += '[';
out += word[j];
out += ']';
flag = true;
}
else
{
out += word[j];
}
}
if (words.size() > 1)
{
out += " ";
}
}
if (!flag)
{
out = "";
for (size_t i = 0; i < words.size(); i++)
{
string word = words[i];
for (size_t j = 0; j < word.size(); j++)
{
if (abbr.find(toupper(word[j])) == abbr.end() && !flag)
{
abbr.insert(toupper(word[j]));
out += '[';
out += word[j];
out += ']';
flag = true;
}
else
{
out += word[j];
}
}
if (words.size() > 1)
{
out += " ";
}
}
cout << out;
}
else
{
cout << out;
}
cout << "\n";
}
return 0;
}
'PS > 백준' 카테고리의 다른 글
1713 - 후보 추천하기 (0) | 2025.02.26 |
---|---|
1421 - 나무꾼 이다솜 (0) | 2025.02.26 |
28066 - 타노스는 요세푸스가 밉다 (0) | 2025.02.25 |
6137 - 문자열 생성 (0) | 2025.02.25 |
3151 - 합이 0 (0) | 2025.02.25 |