2346번: 풍선 터뜨리기

문제접근🤔


놓쳤던 부분😅


#include <iostream>
#include <deque>
#include <utility>
using namespace std;

int main(void)
{
	int n;
	int input;
	int cur;
	pair<int, int> tmp;
	//종이에 적힌 번호, 풍선 번호
	deque<pair<int, int> > ballon;

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> input;
		ballon.push_back({input, i});
	}
	while (!ballon.empty())
	{
		cur = ballon.front().first;
		cout << ballon.front().second << " ";
		ballon.pop_front(); //0
		if (cur > 0)
		{
			for (int i = 0; i < cur - 1; i++)
			{
				tmp = ballon.front();
        ballon.push_back(tmp); //1
				ballon.pop_front(); //2
			}
		}
		if (cur < 0)
		{
			for (int i = 0; i > cur; i--)
			{
				tmp = ballon.back();
        ballon.push_front(tmp); //3
				ballon.pop_back();//4
			}
		}
	}
	return (0);
}

코드😁


2024 KB

0 ms

#include <iostream>
#include <deque>
#include <utility>
using namespace std;

int main(void)
{
	int n;
	int input;
	int cur;
	pair<int, int> tmp;
	//종이에 적힌 번호, 풍선 번호
	deque<pair<int, int> > ballon;

	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> input;
		ballon.push_back({input, i});
	}
	while (!ballon.empty())
	{
		cur = ballon.front().first;
		cout << ballon.front().second << " ";
		ballon.pop_front();
		if (cur > 0)
		{
			for (int i = 0; i < cur - 1; i++)
			{
				tmp = ballon.front();
        ballon.push_back(tmp);
				ballon.pop_front();

			}
		}
		if (cur < 0)
		{
			for (int i = 0; i > cur; i--)
			{
				tmp = ballon.back();
        ballon.push_front(tmp);
				ballon.pop_back();

			}
		}
	}
	return (0);
}