본문 바로가기

Algorithm/시뮬레이션

[백준][3568번][시뮬레이션] iSharp

iSharp

 

https://www.acmicpc.net/problem/3568

 

 

 

 

<문제>

 

 

 

 

 

 

<코드>

 

#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>

using namespace std;
string a,b,c,d,e,temp,ans1,ans2;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	getline(cin, a);
	for (int i = 0; i < a.size(); i++)
	{
		if (a[i] == ' ')
		{
			b = a.substr(0, i);
			c = a.substr(i+1);
			break;
		}
	}
	int cnt = 0;

	for (int i = 0; i < c.size(); i++)
	{
		if (c[i] == ',' || c[i] == ';')
		{
			if (cnt == 0)
				cnt++;
			else
				temp.erase(0,1);
			for (int j = 0; j < temp.size(); j++)
			{
				if (isalpha(temp[j]))
					ans1.push_back(temp[j]);
				else
					ans2.push_back(temp[j]);
			}
			reverse(ans2.begin(), ans2.end());
			for (int k = 0; k < ans2.size(); k++)
			{
				if (ans2[k] == '[')
					ans2[k] = ']';
				else if(ans2[k] == ']')
					ans2[k] = '[';
			}
			cout << b << ans2 << ' ' << ans1<<';'<<endl;
			temp.clear(); ans1.clear(); ans2.clear();
		}
		else
			temp.push_back(c[i]);
	}
}