深圳网站开发是什么,余姚网络公司哪家好,企业网站建设与管理试题,杭州建设网站的公司哪家好题目描述 中午买饭的人特多,食堂真是太拥挤了,买个饭费劲,理工大的小孩还是很聪明的,直接奔政通超市,哈哈,确实,政通超市里面也卖饭,有好几种菜,做的比食堂好吃多了,价格也不比食堂贵,并且买菜就送豆浆,吸引了不少童鞋。所以有时吧#xff0c;人还是很多的#xff0c;排队是免…题目描述 中午买饭的人特多,食堂真是太拥挤了,买个饭费劲,理工大的小孩还是很聪明的,直接奔政通超市,哈哈,确实,政通超市里面也卖饭,有好几种菜,做的比食堂好吃多了,价格也不比食堂贵,并且买菜就送豆浆,吸引了不少童鞋。所以有时吧人还是很多的排队是免不了的悲剧的是超市只有两个收银窗口。 问题是这样的开始有两队人在排队现在咱们只研究第一队现在我们给每个人一个编号保证编号各不相同排在前面的人买完饭就走了有些人挑完饭就排在后面等待付款还有一些人比较聪明看到另一个队人比较少直接离开这个队到另一个队去了。我要问的是队的总人数和某个位置上人的编号。 输入 首先输入一个整数m(m10000)代表当前有m个人第二行输入m个数代表每个人的编号第三行输入一个整数n(n10000)代表队列变动和询问一共n次以后n行JOIN X表示编号为X保证与以前的编号不同的人加入LEAVE Y表示第YY小于当前队列长度个位置 上的人离队 ASK ZZ小于当前队列长度表示询问第Z个位置上的人的编号FINISH D表示有D个人买完饭离开了;LENGTH表示询问队列的长度 。保证所有数据在int 范围内. 输出 对每个询问输出相应的答案每个答案占一行。 示例输入 3 1 2 3 6 JOIN 4 ASK 2 LEAVE 2 LENGTH FINISH 2 LENGTH 示例输出 2 3 1 #include stdio.h #include stdlib.h #includestring.h typedef int QElemType; typedef int Status; typedef struct QNode { QElemType data; QNode *next; }*Queueptr; typedef struct { Queueptr front; Queueptr rear; }LinkQueue; Status InitQueue(LinkQueue q)//初始化队 { q.frontq.rear(Queueptr)malloc(sizeof(QNode)); if(!q.front) exit(0); q.front-nextNULL; return 1; } Status EnQueuer(LinkQueue q,QElemType e)//进队 { Queueptr p; p(Queueptr)malloc(sizeof(QNode)); if(!p) exit(0); p-datae; p-nextNULL; q.rear-nextp; q.rearp; return 1; } Status DeQueuer(LinkQueue q)//出队 { Queueptr p; if(q.frontq.rear) return 0; pq.front-next; q.front-nextp-next; if(q.rearp) q.rearq.front; free(p); return 1; } int LinkQueuelength(LinkQueue q)//队的长度 { Queueptr p; pq.front; int i0; while(p!q.rear) { i; pp-next; } return i; } int main() { int m,i,n,num; char c[7]; LinkQueue q; InitQueue(q); scanf(%d,m); for(i0;im;i) { scanf(%d,num); EnQueuer(q,num); } scanf(%d,n); for(i1;in;i) { scanf(%s,c); if(strcmp(c,JOIN)0) { scanf(%d,num); EnQueuer(q,num); } if(strcmp(c,ASK)0)//问第几个元素的编号 { scanf(%d,num); Queueptr p; pq.front;//指向队头 while(num--) pp-next; printf(%d\n,p-data); } if(strcmp(c,LEAVE)0) { scanf(%d,num); int tnum-1; Queueptr pq.front;//两指针将对中第几个人删除 Queueptr hp-next; while(t--) { pp-next; hh-next; } p-nexth-next;//相当于链表元素的删除 } if(strcmp(c,FINISH)0) { scanf(%d,num); while(num--) DeQueuer(q); } if(strcmp(c,LENGTH)0) { printf(%d\n,LinkQueuelength(q)); } } return 0; } #include iostream #include cstdio #include cstdlib #include cstring using namespace std; int main() { int i,n,m,x,j,l,a[20000]{0}; char str[10]; scanf(%d,n); for(i0;in;i) scanf(%d,a[i]); scanf(%d,m); for(i0;im;i) { scanf(%s,str); if(str[0]J) { scanf(%d,x); a[n]x; } else if(str[0]L) { if(str[2]A) { scanf(%d,x); for(lx-1;ln;l) a[l]a[l1]; n--; } else { printf(%d\n,n); } } else if(str[0]A) { scanf(%d,x); printf(%d\n,a[x-1]); } else if(str[0]F) { scanf(%d,x); if(xn)n0; else { for(j0;jn-x;j) a[j]a[jx]; nn-x; } } } return 0; }*/ #include iostream #include cstdio #include cstdlib #include cstring using namespace std; int main() { int i,n,m,x,j,l,a[100000]{0}; char str[10]; scanf(%d,n); for(i0;in;i) scanf(%d,a[i]); scanf(%d,m); for(i0;im;i) { scanf(%s,str); if(strcmp(str,JOIN)0) { scanf(%d,x); a[n]x; } else if(strcmp(str,LEAVE)0) { scanf(%d,x); for(lx-1;ln;l) a[l]a[l1]; n--; } else if(strcmp(str,LENGTH)0) { printf(%d\n,n); } else if(strcmp(str,ASK)0) { scanf(%d,x); printf(%d\n,a[x-1]); } else // if(strcmp(str,FINISH)0) { scanf(%d,x); if(xn)n0; else { for(j0;jn-x;j) a[j]a[jx]; nn-x; } } } return 0; }