https://www.acmicpc.net/problem/3568
3568번: iSharp
입력으로 주어진 변수 선언문을 문제의 조건에 맞게 변형한 뒤, 한 줄에 하나씩 출력한다. 변수형과 변수명 사이에는 공백이 하나 있어야 한다. 출력은 입력으로 주어진 변수 선언문에서 변수가
www.acmicpc.net
#include <bits/stdc++.h>
std::vector<std::string> answers;
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::string s;
std::getline(std::cin, s);
// 파싱을 편하게 하기 위한 조작
s.pop_back();
s += ", ";
std::stringstream ss;
ss.str(s);
std::string common;
ss >> common;
std::string portion;
while(ss >> portion){
std::string str = common;
// std::cout << portion << "\n";
int idx = portion.length() - 2;
while(true){
if (portion[idx] == ']'){
str += "[]";
--idx;
}
else if ((portion[idx] >= 'a' && portion[idx] >= 'z') || (portion[idx] >= 'A' && portion[idx] >= 'Z')){
break;
}
else {
str += portion[idx];
}
--idx;
}
str += ' ';
str += portion.substr(0, idx + 1);
str += ';';
answers.push_back(str);
}
for (auto str : answers){
std::cout << str << "\n";
}
return 0;
}
'백준 문제풀이 > Parsing' 카테고리의 다른 글
[C++] 백준 문제풀이 (Parsing) 12787번 지금 밥이 문제냐 (0) | 2023.05.28 |
---|---|
[C++] 백준 문제풀이 (Parsing) 3613번 Java vs C++ (0) | 2023.05.27 |