排考场座位问题 c语言

排考场座位问题 c语言,第1张

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

#define ROW 8

#define COL 8

int seat[ROW*COL]={0}

void main()

{

int i,j,k,a,count=0

while(1)

{

system("cls") //清屏

fflush(stdin) //清键盘输入缓冲区

printf("\n\t\t1 设定考场梁悔座位")

printf("\n\t\t2 取消考场座位")

printf("\n\t\t3 显示某座位考生信息")

printf("\n\t\t4 查找学生座位\n\t\t\t退出程序:Ctrl+C\n\n\t请选择:")

k = getchar()

if(k<'1'||k>'4') continue//无效的选择直接忽略

fflush(stdin)

switch (k)

{

case '1':

if(count+1 >= ROW*COL){printf("报歉,坐位已满!")break}

printf("输入准考证号:")

scanf("%d",&k)

for(a=0a<ROW*COLa++) if(seat[a] == k) break//遍历

if(a<ROW*COL)

{

printf("考生%d已经在坐位:%d排%d坐\n",k,a/COL+1,a%COL+1)

break

}

srand((int)time(NULL))

a = rand()%(ROW*COL)

while(seat[a]!=0) a=(a+1)%(ROW*COL)//搜索到一个空坐位

seat[a] = k//放上准考证号

printf("安排在坐位:%d排%d坐\n",a/COL+1,a%COL+1)

break

case '2':

printf("输入准考证号:")

scanf("%d",&k)

for(a=0a<ROW*COLa++) if(seat[a] == k) break//遍历

if(a<ROW*COL)

{

seat[a]=0

printf("取消了考生%d的坐位:%d排%d坐\n",k,a/COL+1,a%COL+1)

}else{

printf("考生%d不在本考场\n",k)

}

break

case '3':

printf("输入坐位几排几坐:")

scanf("%d %d",&i,&j)

if(i<1||i>ROW||j<前贺1||j>COL) printf("没有该坐位:%d排%d坐!")

else

{

k = seat[(i-1)*COL+j-1]

if(k==0) printf("%d排%d坐未安排考生!")

else printf("%d排%d坐考生准考证号:%d",i,j,k)

}

break

case '4':

printf("慧渣派输入准考证号:")

scanf("%d",&k)

for(a=0a<ROW*COLa++) if(seat[a] == k) break//遍历

if(a<ROW*COL)

{

printf("考生%d的坐位:%d排%d坐\n",k,a/COL+1,a%COL+1)

}else{

printf("考生%d不在本考场\n",k)

}

break

}

fflush(stdin)printf("\n回车继续......")

getchar()

}

}

问题还是不少吧,整理了一下,现在扮氏燃没有错误了,至厅虚于逻辑需要自己梳理,仔细体会一下吧。

#include<stdio.h>

#include<stdlib.h>

#include<time.h>

#include<string.h>

typedef struct student

{

char ID[20]

char NAME[20]

}stu

void set(stu stu1[][8])

void delete1(stu stu[][8])

void show(stu student[][8])

void Information(stu stud[][8])

void find(stu stu[][8], int *q, int *p)

void clean()

void main()

{

int pick,choice,x,y

stu stu1[8][8]

for (x=0x<8x++)

{

for (y=0y<8y++ )

{

strcpy(stu1[x][y].ID, "*")

strcpy(stu1[x][y].NAME, "*")

}

}

clean()

do

{

printf("请输入数字:")

scanf("%d",&choice)

getchar()

switch(choice)

{

case 1:set(stu1)break

case 2:delete1(stu1)break

case 3:Information(stu1)break

case 4:find(stu1, &x, &y)break

case 5:show(stu1)break

default: printf("fhsak")

}

printf("继续请按1,退出请按2")

scanf("%d",&pick)

getchar()

}while(pick==1)

}

void set(stu stu1[][8])

{

char id[16]

char name[10]

int x,y,z

srand(time(NULL))

printf("请输入准考证号和姓名(中间以一个空格隔开)")

scanf("%s %s",&id, &name)

z=rand()%64+1

x=z/8+1

y=z%8+1

strcpy(stu1[x][y].ID,id)

strcpy(stu1[x][y].NAME,name)

}

void Information(stu stud[][8])

{

int x,y

printf("请输入查核掘询的考生的座位行号:")

scanf("%d",&x)

printf("请输入查询的考生的座位列号:")

scanf("%d",&y)

puts(stud[x-1][y-1].ID)

puts(stud[x-1][y-1].NAME)

}

void find(stu stu[][8], int *q, int *p)

{

char num[20]

int x,y,i=0

printf("请输入需要查询的考生的准考证号:")

scanf("%s",num)

for(x=0x<8x++)

{

for(y=0y<8y++)

{

if(strcmp(stu[x+1][y+1].ID,num)==0)

{

printf("该考生的考试座位号为%d行,%d列",x,y)

*q=x+1*p=y+1

i++

}

}

}

if(i==0)

printf("不存在此准考证号")

}

void delete1(stu stu1[][8])

{

int *p=NULL, *q=NULL

find(stu1, p, q)

strcpy(stu1[*q][*p].ID,"*")

strcpy(stu1[*q][*p].NAME,"*")

}

void show(stu student[][8])

{

for(int x=1x<9x++)

{

for(int y=1y<9y++)

{

printf("%s",student[x][y].NAME)

}

}

}

void clean()

{

system("cls")

puts(" |----------------------------------------| ")

puts(" | 请输入选项编号(1-5): | ")

puts(" |----------------------------------------| ")

puts(" | 1-设定考场座位 | ")

puts(" | 2-取消考场座位 | ")

puts(" | 3-显示某座位考生信息 | ")

puts(" | 4-查找学生座位 | ")

puts(" | 5-显示考场座次表 | ")

puts(" |----------------------------------------| ")

}

我还有前四题

(1) 基础部分(以下8题,任选5题—60%,多做酌情加分)

①分屏处理数据系统:

随机产生1000个数,并分屏显示(每行显示10个数字,每页显示10行),而且在每一屏的下方显示本屏中数据的最大值、最小值和平均值。

提示:循环显示,在分屏点上输出press any key to continue…,通过getch()函数让用户以按春行回车键的方式进入下一屏。

②掷骰子游戏:

两人玩骰子,游戏规则橘链如下:

1) 两人轮流掷骰子,每次掷两个,每人最多掷10次。

2) 将每人每次的分值累加计分

3) 当两个骰子点数都为6时,计8分;当两个点数相等且不为两个6时,计7分;当两个点数不一样时,计其中点数较小的骰子的点数。

4) 结束条件:当双方都掷10次或经过5次后一方累计分数为另一方的两倍。最后显示双方分数并判定优胜者。

③射击游戏:

在程序运行时屏幕上方第一行随机出现一个符号,要求游戏者输入一个1-200之间的整数,当用户输入一个整数后,一个*立即从屏幕底端的该整数列向上移动,若移动到屏幕的顶端能撞上符号,则游戏者获胜;若没有撞上,则要求再输入一个整数,共允许输入5次,如果一直没有撞上,则认为游戏者输。

提示:

1)输入符号可以采用printf("%c",'\1')

2)显示*号向上移动:输出一些空行;输出*号;以循环的方式增加延时(for(i=0i<100000i++));clrscr()清屏重新绘制*号。

④车票问题:

假设某线路的公共汽车共设置26个车站,准备了1元、2元…6元的车票,收费标准为:6站以内票价为1元,每4站票价增加1元。现在随机生成一些乘客的上车站与下车站扒伍哗,显示每位乘客应付的票价和单程售出的总票价,并统计几元的车票卖得最多。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12558720.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存