码迷,mamicode.com
首页 > 其他好文 > 详细

SDUT OJ 数据结构实验之队列一:排队买饭

时间:2014-12-05 00:50:43      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   sp   for   on   数据   

bubuko.com,布布扣

#include<iostream>
#include<memory.h>
#include<string>
#define N 10010
using namespace std;
int main()
{
	int m,i,a[N],b[N],top,n,y,j;
	string x[N];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	cin>>m;
	top=0;
	for(i=1;i<=m;i++)
	{
		cin>>y;
		a[++top]=y;
	}
	cin>>n;
    j=0;
    for(i=1;i<=n;i++)
	{
		cin>>x[i];
		if(x[i]!="LENGTH")
			cin>>b[i];
	}
	for(i=1;i<=n;i++)
	{
		if(x[i]=="JOIN")
		{
			a[++top]=b[i];
		}
		else if(x[i]=="ASK")
		{
			cout<<a[b[i]]<<endl;
		}
		else if(x[i]=="LEAVE")
		{
            for(int k=b[i];k<=top;k++)
			{
				a[k]=a[k+1];
			}
			top--;
		}
		else if(x[i]=="LENGTH")
		{
			cout<<top<<endl;
		}
        else if(x[i]=="FINISH")
		{
			for(int o=1;o<=top-b[i];o++)
				a[o]=a[o+b[i]];
			top=top-b[i];
		}
	}
	return 0;
}


 

SDUT OJ 数据结构实验之队列一:排队买饭

标签:blog   http   io   ar   os   sp   for   on   数据   

原文地址:http://blog.csdn.net/r_misaya/article/details/41733525

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!