當前位置:首頁 » 編程語言 » 插隊問題中的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;

}