首页 > 其他分享 >,练习题

,练习题

时间:2023-06-25 22:32:20浏览次数:58  
标签:练习题 return int SqQueue else void top


//while (scanf("%d", n) != EOF && n != 0);
////{
////	getchar();
////	for (int i = 0; i < n; i++) {
////		char ch;
////		scanf("%c", &ch);
////		switch (ch) {
////			case 'P':
////				int x;
////				scanf("%d", &x);
////				pushStack(&s, x);
////				break;
////			case 'O':
////				pop(&s);
////				break;
////			case 'A':
////				if (empty(&s))
////					printf(E);
////				else
////					printf(n);
////				break;
////		}
////		getchar();
////	}
////	Free(&s);
////
////}
//#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#define maxsize 100
//#define stype int
//
//typedef struct {
//	stype *base;
//	stype *top;
//	int size;
//} data; //用结构体构造栈的数据类型
//
//int initstack(data *s) {
//	s->base = (stype *)malloc(sizeof(stype) * maxsize);
//
//	if (!s->base) {
//		exit(0);
//		return 0;
//	}
//
//	else {
//		s->top = s->base;
//		s->size = maxsize;
//	}
//}
//
//int getstack(data *s, stype *x) {
//	if (s->base == s->top)
//		return 0;
//
//	else {
//		*x = *(s->top - 1);
//		return 1;
//	}
//}
//
//int pop(data *s, stype *x) {
//	if (s->base == s->top)
//		return 0;
//
//	else {
//		*x = *--s->top;
//		return 1;
//	}
//
//}
//
//int push(data *s, stype x) {
//	if (s->top - s->base == maxsize)
//		return 0;
//
//	else {
//		*s->top++ = x;
//		return 1;
//	}
//}
//
//int main() {
//	int n, k, m, x, flag, i;
//	char ch[5];
//	data s;
//	initstack(&s);
//
//
//	while (scanf("%d", &n), n) {
//		k = 0;
//		while (k < n) {
//			scanf("%s", ch);
//
//			if (strcmp(ch, "P") == 0) {
//				scanf("%d", &m);
//				push(&s, m);
//			}
//
//			else if (strcmp(ch, "O") == 0) {
//				pop(&s, &x);
//			}
//
//			else if (strcmp(ch, "A") == 0) {
//				flag = getstack(&s, &x);
//
//				if (flag == 0)
//					printf("E\n");
//				else
//					printf("%d\n", x);
//			}
//
//			k++;
//		}
//
//		while (s.base != s.top)
//			pop(&s, &x);
//
//		putchar('\n');
//	}
//
//	return 0;
//}
//
//typedef struct Stack {
//	int *data;
//	int length;
//	int top;
//} *Stack, stack_s;
//void initStack(Stack s) {
//	S->top = -1;
//}
//void push(Stack s, int x) {
//	if (s->top + 1 >= s->length)
//		return ;
//	else
//		s->data[++s->top] = x;
//}
//void pop(Stack s) {
//	if (s->top == -1)
//		return ;
//	else
//		s->top--;
//}
//int gettop(Stack s) {
//	if (s->top == -1)
//		return ;
//	int x;
//	x = s->data[s->top];
//	return x;
//}
//int main() {
//	char c[2];
//	int n;
//	Stack s;
//	while (scanf("%d", &n) && n) {
//		getchar();
//		initStack(S);
//		s->length = n;
//		s->data = malloc...
//
//		for (int i = 0; i < n; i++) {
//			scanf("%s", c);
//			switch (c[0]) {
//					case...
//			}
//
//		}
//	}
//}//#include <stdio.h>

//Queue q;
//Queue q1;
//Queue q2;
//void manager()
//{
//	int i=0,j=0;
//	while(j<10){
//	if(!emptyQueue(q1)&&i<4)
//	{
//		deQueue(q1,x);
//		enQueue(q,x);
//		i++;
//		j++;
//	}
//	else if(i==4&&!emptyQueue(q1))
//	{
//		deQueue(q2,x);
//		enQueue(q,x);
//		j++;
//		i=0;
//	}
//	else
//	{
//		while(j<10&&i<4&&!emptyQueue(q2))
//		{
//			deQueue(q2,x);
//			enQueue(q,x);
//			j++;
//			i++;
//		}
//		i=0;
//	}
//		if(emptyQueue(&q1)&&emptyQueue(&q2))
//		{
//			break;
//		}
//   }
//}


#include <stdio.h>

#define MaxSize 11

typedef char ElemType;

typedef struct {
	ElemType data[MaxSize];
	int front, rear;
} SqQueue;

void InitQueue(SqQueue *Q);
void EnQueue(SqQueue *Q, ElemType x);
void DeQueue(SqQueue *Q, ElemType *x);
int IsEmpty(SqQueue *Q);
void Manager(SqQueue *Q, SqQueue *Qp, SqQueue *Qt);
void PrintQueue(SqQueue Q);

int main(int argc, char *argv[]) {
	SqQueue Q;
	SqQueue Qp;  // 客车队列
	SqQueue Qt;  // 货车队列

	InitQueue(&Q);
	InitQueue(&Qp);
	InitQueue(&Qt);

	ElemType x = 'P';
	for (int i = 0; i < 3; i++) {
		EnQueue(&Qp, x);
	}
	ElemType y = 'T';
	for (int i = 0; i < 6; i++) {
		EnQueue(&Qt, y);
	}

	Manager(&Q, &Qp, &Qt);

	PrintQueue(Q);

	return 0;
}

void InitQueue(SqQueue *Q) {
	Q->front = 0;
	Q->rear = 0;
}

void EnQueue(SqQueue *Q, ElemType x) {
	if (Q->rear == MaxSize - 1) {
		return;
	}
	Q->data[Q->rear++] = x;
}

void DeQueue(SqQueue *Q, ElemType *x) {
	if (Q->front == Q->rear) {
		return;
	}
	*x = Q->data[Q->front++];
}

int IsEmpty(SqQueue *Q) {
	if (Q->front == Q->rear) {
		return 1;
	} else {
		return 0;
	}
}

void Manager(SqQueue *Q, SqQueue *Qp, SqQueue *Qt) {// 客车队列Qp// 货车队列Qt
	int count = 0;
	int car = 0;
	ElemType e;

	// 渡口模拟
	while (count < MaxSize) {
		if (IsEmpty(Qp) && IsEmpty(Qt)) {
			break;
		}

		if (!IsEmpty(Qp) && car < 4) {
			DeQueue(Qp, &e);
			EnQueue(Q, e);
			car++;
			count++;
		} else if (car == 4 && !IsEmpty(Qt)) {
			DeQueue(Qt, &e);
			EnQueue(Q, e);
			count++;
			car = 0;
		} else if (IsEmpty(Qp) && !IsEmpty(Qt)) {
			while (count < MaxSize && !IsEmpty(Qt)) {
				DeQueue(Qt, &e);
				EnQueue(Q, e);
				count++;
			}
		} else {
			break;
		}
	}
}

void PrintQueue(SqQueue Q) {
	while (Q.front != Q.rear) {
		printf("%c", Q.data[Q.front++]);
	}
	printf("\n");
}


标签:练习题,return,int,SqQueue,else,void,top
From: https://blog.51cto.com/u_16030624/6549382

相关文章

  • Scala练习题
    SQLjoin语法案例Data:order.txtorder011,u001,300order012,u002,200order023,u006,100order056,u007,300order066,u003,500order055,u004,300order021,u005,300order014,u001,100order025,u005,300order046,u007,30order067,u003,340order098,u008,310user.txt......
  • MYSQL经典练习题
    题目来源:https://blog.csdn.net/flycat296/article/details/63681089Github地址:https://github.com/bladeXue/sql50添加测试数据库信息#创建数据库createdatabasesql50;usesql50;#学生表createtableStudent(SIdvarchar(10),Snamevarchar(10),Sagedatetime,Sse......
  • C++练习题
    多态判断Q1:虚函数可以是内联的?A1:错误。内联是编译时刻决定的,虚函数是运行时刻动态决定的,所以虚函数不能是内联函数。虚函数前加上inline不会报错,但是会被忽略。Q2:一个类内部,可以同时声明staticvoidfun()和virutalvoidfun()两个函数?A2:错误。虽然静态函数......
  • python基础语法练习题
    """一、必做题1、下面变量名正确的是(ABD)A.nameB.num1C.1_numD.name_A_12、Python不支持的数据类型有(A)A、charB、intC、floatD、list3、python源程序执行的方式(B)A编译执行B解析执行C直接执行D边编译边执行4、Python语言语句块的标记是(C)A分号B......
  • 2小时解不完的数据库练习题,来挑战一下吧!
    写在前面我已经记不起来,有多久没更新文章了。5月中旬我还在上班,中旬以后一系列发生的事情,真的远远超出了可承受范围,只能硬着头皮面对!我是谁,我应该是谁,又能怎样,只能向前·····数据库实例class表course表score表student表teacher表实际语句1、查询所有的课程的......
  • [MtOI2019]幽灵乐团 / 莫比乌斯反演基础练习题
    [MtOI2019]幽灵乐团/莫比乌斯反演基础练习题题目描述东风谷早苗(KochiyaSanae)非常喜欢幽灵乐团的演奏,她想对她们的演奏评分。因为幽灵乐团有\(3\)个人,所以我们可以用\(3\)个正整数\(A,B,C\)来表示出乐团演奏的分数,她们的演奏分数可以表示为\[\prod_{i=1}^{A}\prod_......
  • lightdb 练习题
    lightdb练习题在LightDB/PostgreSQL中,有表a,定义为:createtablea(idintprimarykey,randint,commvarchar(128));如何一条语句生成一张1000万记录的表,且满足id从1001万-2000万,rand为0-1000000之间的随机整数,comm为随机生成的UUID?insertintoaselect*,random()......
  • P5518 [MtOI2019]幽灵乐团 / 莫比乌斯反演基础练习题
    简要题意计算\[\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}\left(\frac{\text{lcm}(i,j)}{\gcd(i,k)}\right)^{f(type)}\]其中:\[\begin{aligned}f(0)&=1\crf(1)&=i\timesj\timesk\crf(2)&=\gcd(i,j,k)\end{aligned}\]\(T\)组数据,每......
  • ansible练习题1-2
    ansible大结局-练习Cloud研习社 Cloud研习社 2023-05-1807:31 发表于山东收录于合集#一站式教程235个#云计算225个#linux237个#ansible38个教程每周二、四、六更新ansible的全部知识点在前面已经全部更新完毕了,剩下的任务就是多加练习。今天我们做个题目......
  • PTA练习题
    定义一个Dog类,包括体重和年龄两个数据成员及其成员函数,声明一个实例dog1,体重5,年龄10,使用I/O流把dog1的状态写入磁盘文件。再声明一个实例dog2,通过读取文件dog1的状态赋给dog2。分别用文本方式和二进制方式操作文件。1#include<iostream>2#include<fstream>3usingname......