当前位置:首页 » 编程语言 » 插队问题中的c语言描述
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

插队问题中的c语言描述

发布时间: 2022-11-04 20:33:02

c语言求助:

就是设置一个乘客的链表
先进先出,然后插队和离开的就用链表的插入和删除的算法
车的话就是再设置一个链表然后与前面的链表对应就可以了。

㈡ C语言银行排队系统

你所指的队列是线程吗?
线程操作,大概思路如下:
1. 创建4个线程,表示四个窗口,用semaphore来等待客户进入(WaitForSingleObject).
2. 创建n个线程表示客户,每创建一个客户增加一个ReleaseSemaphore,以让窗口处理(记录相关信息,随机时间可以用srand获取),窗口要设定为while循环,可以多次处理,条件可以设置为处理多少个客户就可以退出.
3. 共用资源记得设置临界区CriticalSection.

㈢ C语言程序设计题目:编写模拟同学排队打饭程序

代码: #include"stdio.h"
#include"stdlib.h"
#include"conio.h"
#include"string.h"
#include"io.h"

#define ESC 27
#define ENTER 13
#define Y 89
#define y 121
#define N 78
#define n 110

void vmenu1();
char choose();
void password();
char *getps();
void mimam();
void build();
void save();
void buy();
void open1();
void modify();
void modifyM();
void XnumM();
void XclassM();
void XnameM();
void add();
void xuehaoA();
void xingmingA();
void query();
void xuehaoQ();
void xingmingQ();
void delete1();
void xuehaoD();
void xingmingD();
void sort();
void sortX();
void sortN();
void sortA();
void all();
void help();
void lock();
void exit1();

struct record
{
char cnumber[15];
char cclass[15];
char cname[15];
char cmoney[10];
char cspend[10];
struct record *next;
};
struct sot
{
char ccnumber[15];
struct sot *pnext;
};
struct address
{
char *adss;
struct address *anext;
};
struct sot *chead=NULL;
struct record *head=NULL,*ppointer=NULL,*temp;
struct record *modf;
struct address *ahead=NULL;
FILE *fp;

int Fflag=0;
int counts=0;
int loop=0;

void main()
{
char menu;
password();
while(loop==0)
{
system("CLS");
vmenu1();
menu=choose();
switch(menu)
{
case '1':build();break;
case '2':count++;
if(count==1)
{
buy();
break;
}
else
{
chead=NULL;
buy();
break;
}
case '3':open1();break;
case '4':modify();k=0;break;
case '6':query();break;
case '7':delete1();break;
case '9':all();break;
case 'b':help();break;
case 'c':lock();break;
case 'd':{loop=1;exit1();break;}
default:
printf("----------------------------请输入菜单上的序号 ------------------------\n");
printf("---------------------------按任意键重新开始选择 -----------------------\n");
fflush(stdin);
a=getch();
}

}
}
void password()
{
char password[15];
char *password1;
char *password2;
char p1[15];
char p2[15];
char a;
int i;
int count=0;
if(access("c:\\mima.txt",00)!=0)
{
while(1)
{
system("CLS");
for(i=0;i<5;i++)
printf("\n");
printf("\t\t欢迎使用学生打饭系统!\n\n");
printf("\n");
printf("\n----------------------------请创建管理员密码:--------------------------------\n");
password1=getps();
for(i=0;i<15;i++)
p1[i]=*(password1++);
printf("\n");
printf("\n----------------------------请再输入一次密码:--------------------------------\n");
password2=getps();
for(i=0;i<15;i++)
p2[i]=*(password2++);
if(!strcmp(p1,p2))
{
if((fp=fopen("c:\\mima.txt","w"))==NULL)
{
printf("错误!\n");
exit(0);
}
else
{
fprintf(fp,"%s",p1);
printf("\n密码创建完毕!\n");
fclose(fp);
system("cmd.exe /c attrib c:\\mima.txt +h");
break;
}
}
else
{
printf("两次输入不一致,请重新输入密码:\n");
}
}
}
else
{
while(1)
{
count++;
for(i=0;i<5;i++)
printf("\n");
printf("----------------------------请输入管理员密码:----------------------------------\n");
password1=getps();
for(i=0;i<15;i++)
p1[i]=*(password1++);
if((fp=fopen("c:\\mima.txt","r"))==NULL)
{
printf("错误!\n");
exit(0);
}
else
{
fscanf(fp,"%s",password);
fclose(fp);
if(!strcmp(p1,password))
break;
else
printf("\n密码错误!\n");
}
if(count<=9)
{
printf("\n您还有%d次机会。。。。。。\n",10-count);
printf("\n\n\n-------------------请按除ESC外的任意按键重新输入密码!----------------------\n");
a=getch();
if(a==ESC)
exit(0);
}
if(count==10)
{
printf("\n\n您无权使用本系统!\n");
printf("按任意键退出。。。。。。\n");
fflush(stdin);
a=getch();
exit(0);
}
}
}
printf("\n\n\n是否要对密码进行修改?\n");
printf("\t按Y或y更改,其余按键进入系统。\n");
fflush(stdin);
a=getchar();
if(a==Y||a==y)
{
mimam();
}
system("CLS");
for(i=0;i<5;i++)
printf("\n");
printf("\t\t欢迎使用学生打饭系统!\n\n");
printf(" ");
printf("\t\t按任意键进入系统。。。。。。\n\n");
a=getch();
}
char *getps()
{
char p[15];
password=p;
while(1)
{
fflush(stdin);
*password=getch();
if(*password==ENTER)
{
break;
}
putchar('*');
password++;
}
*password='\0';
password=p;
return(password);
}

㈣ c语言程序:插队问题

#include <stdio.h>


int main()

{

float a[11] = {

1.73,1.75,1.78,1.81,1.84,1.87,1.88,1.88,1.89,1.90

};

float b = 1.82;

int i;

for(i = 9; i >= 0; --i) {

if(a[i] > b) a[i+1] = a[i];

else break;

}

a[i+1] = b;

for(i=0;i<11;++i) printf("%.2f ", a[i]);

}


㈤ C语言栈和队列问题:停车场停车问题

#ifndef__PLOT_H__#define__PLOT_H__#defineFALSE0#defineTRUE1#defineMONEY1//单价可以自己定义#defineMAX_STOP10#defineMAX_PAVE100//存放汽车牌号typedefstruct{

inttime1;//进入停车场时间
inttime2;//离开停车场时间
charplate[10];
//汽车牌照号码,定义一个字符指针类型}Car;//停放栈typedefstruct{
CarStop[MAX_STOP-1];//各汽车信息的存储空间
inttop;//用来指示栈顶位置的静态指针}Stopping;//等候队列typedefstruct{intcount;//用来指示队中的数据个数
CarPave[MAX_PAVE-1];//各汽车信息的存储空间
intfront,rear;//用来指示队头和队尾位置的静态指针}Pavement;//让路栈typedefstruct{
CarHelp[MAX_STOP-1];//各汽车信息的存储空间
inttop;//用来指示栈顶位置的静态指针}Buffer;

Stoppings;
Pavementp;
Bufferb;
Carc;charC[10];voidstop_pave();//车停入便道voidcar_come();//车停入停车位voidstop_to_buff();//车进入让路栈voidcar_leave();//车离开voidwelcome();//主界面函数voidDisplay();//显示车辆信息#
源文件PLot.c
#include"PLot.h"#include<stdio.h>#include<time.h>//包含时间函数的头文件#include<string.h>#include<stdlib.h>voidstop_to_pave()//车停入便道{//判断队满
if(p.count>0&&(p.front==(p.rear+1)%MAX_PAVE))
{printf("便道已满,请下次再来 ");
}else
{strcpy(p.Pave[p.rear].plate,C);
p.rear=(p.rear+1)%MAX_PAVE;//队尾指示器加1
p.count++;//计数器加1
printf("牌照为%s的汽车停入便道上的%d的位置 ",C,p.rear);
}
}voidcar_come()//车停入停车位{printf("请输入即将停车的车牌号:");//输入车牌号
scanf("%s",&C);if(s.top>=MAX_STOP-1)//如果停车位已满,停入便道
{
stop_to_pave();//停车位->便道函数
}else
{
s.top++;//停车位栈顶指针加1
time_tt1;longintt=time(&t1);//标记进入停车场的时间
char*t2;
t2=ctime(&t1);//获取当前时间
c.time1=t;strcpy(s.Stop[s.top].plate,C);//将车牌号登记
printf("牌照为%s的汽车停入停车位的%d车位,当前时间:%s ",C,s.top+1,t2);
}return;
}voidstop_to_buff()//车进入让路栈{//停车位栈压入临时栈,为需要出栈的车辆让出道
while(s.top>=0)
{
if(0==strcmp(s.Stop[s.top--].plate,C))
{break;
}//让出的车进入让路栈
strcpy(b.Help[b.top++].plate,s.Stop[s.top+1].plate);printf("牌照为%s的汽车暂时退出停车位 ",s.Stop[s.top+1].plate);
}
b.top--;//如果停车位中的车都让了道,说明停车位中无车辆需要出行
if(s.top<-1)
{printf("停车位上无此车消息 ");
}else
{printf("牌照为%s的汽车从停车场开走 ",s.Stop[s.top+1].plate);
}//将让路栈中的车辆信息压入停车位栈
while(b.top>=0)
{strcpy(s.Stop[++s.top].plate,b.Help[b.top--].plate);printf("牌照为%s的汽车停回停车位%d车位 ",b.Help[b.top+1].plate,s.top+1);
}//从便道中->停车位
while(s.top<MAX_STOP-1)
{if(0==p.count)//判断队列是否为空
{break;
}//不为空,将便道中优先级高的车停入停车位
else
{strcpy(s.Stop[++s.top].plate,p.Pave[p.front].plate);printf("牌照为%s的汽车从便道中进入停车位的%d车位 ",p.Pave[p.front].plate,s.top+1);
p.front=(p.front+1)%MAX_PAVE;
p.count--;
}
}
}voidcar_leave()//车离开{printf("请输入即将离开的车牌号: ");scanf("%s",&C);if(s.top<0)//判断停车位是否有车辆信息
{printf("车位已空,无车辆信息! ");
}else
{
stop_to_buff();
}

time_tt1;
longintt=time(&t1);
c.time2=t;//标记离开停车场的时间
char*t2;
t2=ctime(&t1);//获取当前时间
printf("离开时间%s 需付%ld元 ",t2,MONEY*(c.time2-c.time1)/10);
}voidDisplay()
{inti=s.top;if(-1==i)
{printf("停车场为空 ");
}
time_tt1;longintt=time(&t1);//标记显示时的时间
printf(" 车牌号 停放时间 当前所需支付金额 ");while(i!=-1)
{
printf(" %s %d秒 %d元 ",s.Stop[i].plate,t-c.time1,MONEY*(t-c.time1)/10);
i--;
}
}voidwelcome()
{printf(" *******************目前停车场状况*********************** ");printf(" 停车场共有%d个车位,当前停车场共有%d辆车,等候区共有%d辆车 ",MAX_STOP,s.top+1,(p.rear+MAX_PAVE-p.front)
%MAX_PAVE);printf(" ******************************************************** ");printf(" ---------------WelcometoourCarParking--------------- ");
printf(" *1.Parking* ");
printf(" *2.leaving* ");
printf(" *3.situation* ");
printf(" *4.exit* ");
printf(" -------------------------------------------------------- ");
}


主函数main.c
/**********************************************************
问题描述:停车场是一个能放n辆车的狭长通道,只有一个大门,
汽车按到达的先后次序停放。若车场满了,车要在门外的便道上等候
,一旦有车走,则便道上第一辆车进入。当停车场中的车离开时,由
于通道窄,在它后面的车要先退出,待它走后依次进入。汽车离开
时按停放时间收费。
基本功能要求:
1)建立三个数据结构分别是:停放队列,让路栈,等候队列
2)输入数据模拟管理过程,数据(入或出,车号)。
***********************************************************/#include"PLot.h"intmain()
{//初始化
s.top=-1;
b.top=0;
p.rear=0;
p.count=0;
p.front=0;while(1)
{
system("clear");
welcome();inti,cho;
scanf("%d",&i);if(1==i)car_come();
if(2==i)car_leave();if(3==i)Display();if(4==i)break;

printf("返回请输入1 ");
scanf("%d",&cho);if(1==cho)
{continue;
}else
{
printf("您的输入有误,请重新输入 ");
scanf("%d",&cho);continue;
}
}return0;
}

㈥ C语言模拟排队编程,急求完整答案

这个题有够无聊的,
不过这明显是个基础教学用PPT,是帮助理解的案例,不是用来考人的,
那这些模拟数字应该都是直接写入的吧:
//state1
int q[10];
//state2
q[0] = 9;
q[1] = 5;
q[2] = 2;
q[3] = 7;
//state3
q[4] = 6;
q[5] = 4;
//state4
for(int i = 0;i < 4;i++){q[i] = q[i+2];}
q[4] = 0;q[5] = 0;
//state5
for(int i = 4;i >= 3;i--){q[i] = q[i-1];}
q[4] = 3;
//state6
int k;
for(int i = 0;i <= 4;i++){if(q[i] == 3){k = i;break;}}
//state7
for(int i = k;i < 4;i++){q[i] = q[i+1];}
q[4] = 0;
//state8
for(int i = 0;i < 4;i++){cout<<q[i];}

㈦ C语言排队插队问题以数字代表人数。例如输入12534,5插队了就输出数字1;654321,就是65432插队了,输出5

5插队了干嘛输出1,还有654321就是65432插队输出5,你想干嘛呀,说都说不清

㈧ 关于C语言的问题

这时类似acm的题目
在这种没有说明输入数据组数的情况下,直接按照无穷个输入处理就行。
例如此题,你就写成
while(scanf("%c",&ch)!= EOF)
{
}

这样就可以!
在类似acm的题目中,都是这样解决的!

㈨ 急求插队问题的C语言描述

这题真麻烦,终于写完了。
我得思路是这样的,这道题其实就是维护2个队列。
我把每个组的人当成一个人,而这些人排队就可以看成组与组之间的排队,这是第一个队列,也就是gqueue
然后每个组也都是一个队列,里面顺序排着每个组的人。
描述完成了,然后就是进队出队的问题了。
进队时首先查看自己所在的组有没有在gqueue中,team_in数组保存了每个组在gqueue中的位置,当然一开始都是-1,表示没有入队。如果自己的组在gqueue中,那么就直接加入自己所在组的队列中。如果没有自己的组,就让他所代表的组入gqueue。
出队时出gqueue中第一个组的第一个人,判断一下这个组是不是没有人了,要是没有人了就把这个组dequeue。
大概思路就是这样,还有要注意的就是我用h_table存储哈西表,代表着每个人所在的组的编号,这样把人名shash以下就可以知道他所处的组。
#include<stdio.h>
#include<string.h>

structperson
{
charname[5];
intteam;
};

structpqueue //组内队列
{
personp[1001];
inthead,tail;
};

structgqueue //组队列
{
pqueuepq[1001];
inthead,tail;
};

intn,h_table[100000],team_in[1001];
gqueueq;

voidp_enqueue(persona,pqueue&q)
{
q.p[q.tail]=a;
q.tail++;
if(q.tail==1001)
q.tail=0;
}

voidg_enqueue(persona,gqueue&q)
{
if(team_in[a.team]!=-1)
p_enqueue(a,q.pq[team_in[a.team]]);
else
{
q.pq[q.tail].head=0;
q.pq[q.tail].tail=0;
team_in[a.team]=q.tail;
p_enqueue(a,q.pq[q.tail]);
q.tail++;
if(q.tail==1001)
q.tail=0;
}
}

voidp_dequeue(pqueue&q)
{
printf("%s\n",q.p[q.head].name);
q.head++;
if(q.head==1001)
q.head=0;
}

persong_dequeue(gqueue&q)
{
intt=q.pq[q.head].p[q.pq[q.head].head].team;
p_dequeue(q.pq[q.head]);
if(q.pq[q.head].tail==q.pq[q.head].head)
{
team_in[t]=-1;
q.head++;
if(q.head==1001)
q.head=0;
}
}

intshash(char*key)
{
unsignedlongh=0;
while(*key)
{
h=(h<<4)+*key++;
unsignedlongg=h&0Xf0000000L;
if(g)h^=g>>24;
h&=~g;
}
returnh%100000;
}

voidinit()
{
inti,j,t;
personper;;
for(i=0;i<n;i++)
{
team_in[i]=-1;
scanf("%d",&t);
for(j=0;j<t;j++)
{
scanf("%s",per.name);
per.team=i;
h_table[shash(per.name)]=i;
}
}
q.head=q.tail=0;
}

voidwork()
{
charcommand[10];
personper;
while(scanf("%s",command)!=EOF)
{
if(strcmp(command,"STOP")==0)
break;
if(strcmp(command,"DEQUEUE")==0)
g_dequeue(q);
if(strcmp(command,"ENQUEUE")==0)
{
scanf("%s",per.name);
per.team=h_table[shash(per.name)];
g_enqueue(per,q);
}
}
}
intmain()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
inttime=1;
while(scanf("%d",&n)!=EOF&&n)
{
printf("Scenario#%d\n",time++);
init();
work();
}
return0;
}

㈩ c语言程序:插队问题:有一个10个人的队伍,他们的身高分别为:1.73,1.75,1.7

#include<stdio.h>

int main()

{

float x=1.82,a[10]={1.73,1.75,1.78,1.84,1.88,1.89,1.90};

int i,j,n=7;

for(i=n-1;i>=0&&a[i]>x;i--)

a[i+1]=a[i];

a[i+1]=x;

n++;

for(i=0;i<n;i++)

printf("%.2f ",a[i]);

printf(" ");

return 0;

}