问题 3870 --FCFS(完善程序)

3870: FCFS(完善程序)★★

时间限制: 1 Sec  内存限制: 128 MB
提交: 276  解决: 163
[提交][状态][命题人:]

题目描述

先来先服务调度算法(first come first service)是操作系统调度进程的简单算法。假设有若干个进程在就绪队列中等待执行,则优先执行最早进入队列的进程,执行完毕后,将进程弹出队列。

现在,需要你来模拟FCFS算法。

#include<bits/stdc++.h>
using namespace std;

char que[100];
int head,tail,mod;

bool isFull()
{
	if(____(1)_____)
	{
		printf("is full\n");
		return true;
	}
	else
		return false;
}

bool isEmpty()
{
	if(_____(2)____)
	{
		printf("is empty\n");
		return true;
	}
	else
		return false;
}

void push(char pro)
{
	if(!isFull())
	{
		______(3)_____;
		que[head]=pro;
	}
}

void pop()
{
	if(!isEmpty())
	{
		tail=(tail+1)%mod;
		printf("%c\n",____(4)_____);
	}
}

int main()
{
	int n,opt;
	char pro;
	scanf("%d%d",&n,&mod);
	head=0;
	tail=0;
	while(n--)
	{
		scanf("%d",&opt);
		if(opt==1)
		{
			scanf(" %c",&pro);
			push(pro);
		}
		else if(opt==2)
			pop();
	}
}

输入

详见程序

输出

详见程序
样例输入
Copy
5 5
1 A
1 B
2
1 C
2
样例输出
Copy
A
B

提示

来源

[提交][状态]