메모리

시간

1228 KB

4 ms

Code

#include <queue>
#include <cstdio>
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	queue <int> que;
	for (int i = 0; i < n; i++)
	{
		char str[6];
		scanf("%s", str);
		if (str[1] == 'u')
		{
			int x;
			scanf("%d", &x);
			que.push(x);
		}
		else if (str[1] == 'o')
		{
			if (!que.empty())
			{
				printf("%d\\n", que.front());
				que.pop();
			}
			else
				printf("%d\\n", -1);
		}
		else if (str[0] == 's')
			printf("%lu\\n", que.size());
		else if (str[0] == 'e')
		{
			if (que.empty())
				printf("%d\\n", 1);
			else
				printf("%d\\n", 0);
		}
		else if (str[0] == 'f')
		{
			if (!que.empty())
				printf("%d\\n", que.front());
			else
				printf("%d\\n", -1);
		}
		else if (str[0] == 'b')
		{
			if (!que.empty())
				printf("%d\\n",que.back());
			else
				printf("%d\\n", -1);
		}
	}
	return 0;
}

문제 풀이

입력값에 따라 큐를 컨트롤 하여 출력하는 문제이다.

배열로 큐를 구현하지 않고 간단히 라이브러리 큐를 사용했다.