#include <iostream>
#include <stack>
using namespace std;
int main()
{
string input;
cin >> input;
stack <char> s;
for (int i = 0; i < input.length(); i++)
{
if (input[i] >= 'A' && input[i] <= 'Z')
{
cout << input[i];
}
else if (input[i] == '(')
{
s.push(input[i]);
}
else if (input[i] == ')')
{
while (1)
{
if (s.top() == '(')
{
s.pop();
break;
}
else
{
cout << s.top();
s.pop();
}
}
}
else if(input[i] == '*' || input[i] == '/')
{
while(!s.empty() && (s.top() == '*' || s.top() == '/'))
{
cout << s.top();
s.pop();
}
s.push(input[i]);
}
else if (input[i] == '+' || input[i] == '-')
{
while(!s.empty() && (s.top() != '('))
{
cout << s.top();
s.pop();
}
s.push(input[i]);
}
}
while (!s.empty())
{
cout << s.top();
s.pop();
}
return 0;
}
'프로그래밍 공부 > 백준 (C++)' 카테고리의 다른 글
[C++/백준 2004번] 조합 0의 개수 (0) | 2024.10.26 |
---|---|
[C++/백준 6588번] 골드바흐의 추측 (0) | 2024.10.25 |
[C++/백준 1935번] 후위 표기식 2 (0) | 2024.10.24 |
[C++/백준 17298번] 오등큰수 (0) | 2024.10.24 |
[C++/백준 17298번] 오큰수 (0) | 2024.10.24 |