病人排队(信息学奥赛一本通-T1183)

【题目描述】

病人登记看病,编写一个程序,将登记的病人按照以下原则排出看病的先后顺序:

1.老年人(年龄 >= 60岁)比非老年人优先看病。

2.老年人按年龄从大到小的顺序看病,年龄相同的按登记的先后顺序排序。

3.非老年人按登记的先后顺序看病。

【输入】

第1行,输入一个小于100的正整数,表示病人的个数;

后面按照病人登记的先后顺序,每行输入一个病人的信息,包括:一个长度小于10的字符串表示病人的ID(每个病人的ID各不相同且只含数字和字母),一个整数表示病人的年龄,中间用单个空格隔开。

【输出】

按排好的看病顺序输出病人的ID,每行一个。

【输入样例】

5
021075 40
004003 15
010158 67
021033 75
102012 30

【输出样例】

021033
010158
021075
004003
102012

【源程序】

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
struct node{
    char id[20];
    int age;
    int seq;
}a[110],b[110],temp;
int main()
{
    int n,d;
    char s[20];
    int p=0,q=0,k=0;
    int i,j;

    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s>>d;
        k++;
        if(d>=60)
        {
            strcpy(a[p].id,s);
            a[p].age=d;
            a[p].seq=k;
            p++;
        }
        else
        {
            strcpy(b[q].id,s);
            b[q].age=d;
            b[q].seq=k;
            q++;
        }
    }

    for(i=0;i<p;i++)
        for(j=i+1;j<p;j++)
            if(a[i].age<a[j].age)
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
            else if(a[i].age==a[j].age&&a[i].seq>a[j].seq)
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }

    for(i=0;i<q;i++)
        for(j=i+1;j<q;j++)
            if(b[i].seq>b[j].seq)
            {
                temp=b[i];
                b[i]=b[j];
                b[j]=temp;
            }

    for(i=0;i<p;i++)
        cout<<a[i].id<<endl;
    for(i=0;i<q;i++)
        cout<<b[i].id<<endl;

    return 0;
}

 

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
//活期储蓄处理中,储户开户、销户、存入、支出活动频繁,系统设计要求: //1)能比较迅速地找到储户的帐户,以实现存款、取款记账; //2)能比较简单,迅速地实现插入和删除,以实现开户和销户的需要。 #include #include #include using namespace std; int total; //初始时银行现存资金总额 int closeTime; //营业结束时间 int arriveTime; //两个到达事件之间的间隔上限 int dealTime; //客户之间交易的时间上限 int dealMoney = 30000; //交易额上限 int currentTime = 0; //当前时间 int totalTime = 0; //客户逗留总时间 int counter = 0; //客户总数 int number = 1; //初始客户序列号+ struct service { int num; //客户号 string type; //到达或离开 int beginTime; int endTime; int money; //正数为存款,负数为取款 service* next; }; struct queue { //队列 service* head; service* rear; }; void push(queue &q,int d) {// 插入元素d为Q的新的队尾元素 service* temp = new service; temp->money = d; temp->next = NULL; if(NULL == q.head) {//队列为空,初始化 q. head = temp; q. rear = temp; }//if else {//队列不为空,插入元素d q. rear->next = temp; q. rear = q.rear->next; }//else } void pop(queue &q) {// 若队列不空,出对列函数 service* temp; temp = q. head; if(NULL ==q. head->next) q.head = q. rear =NULL; else q. head=q. head->next; delete temp; } service* front(queue &q) {//返回队首元素 return q. head; } service* back(queue &q) {//返回队尾元素 return q. rear; } service* searchAndDel(queue &q,int m) {//在队列中寻找可处理元素 service* sign = q. head; //标记头节点 service* temp; while(NULL != q. head) { if((-(q. head->money)) next; // 首节点后移一位,返回原首节点 return temp; // 开办.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "stdlib.h" #include "string.h" #include "ctype.h" #include #include /* ---------------- */ void apply(); /* 申请帐号 */ void land(); /* 登陆系统 */ void finds(); /* 查询存款 */ void saving(); /* 存钱 */ void get(); /* 取款 */ void turn(); /* 转帐 */ /* --------------------- */ struct per { char name[20]; char accounts[20]; char password[20]; int money; }dat,temp; /* ----------- */ void manage() /* 主函
下面是实现上述功能的 Python 代码: ```python # 定义一个空的病人排队队列 patient_queue = [] # 定义一个变量,用于记录就诊号的生成 visit_number = 0 while True: # 显示菜单选项 print("请选择操作:") print("1. 挂号") print("2. 排队") print("3. 就诊") print("4. 查看排队") print("5. 下班") # 获取用户输入的选项 choice = input() if choice == "1": # 挂号 print("请输入病人姓名:") name = input() print("请输入病人年龄:") age = input() print("请选择科室:") print("1. 内科") print("2. 外科") print("3. 儿科") department_choice = input() if department_choice == "1": department = "内科" elif department_choice == "2": department = "外科" elif department_choice == "3": department = "儿科" else: print("输入有误,请重新选择科室。") continue # 生成就诊号 visit_number += 1 print("预检完成,分科室为 {},就诊号为 {}。".format(department, visit_number)) elif choice == "2": # 排队 print("请输入病人就诊号:") visit_number = int(input()) patient_queue.append(visit_number) print("病人就诊号为 {} 的病人排队。".format(visit_number)) elif choice == "3": # 就诊 if len(patient_queue) == 0: print("当前没有病人排队。") else: visit_number = patient_queue.pop(0) print("病人就诊号为 {} 的病人已进入诊室就诊。".format(visit_number)) elif choice == "4": # 查看排队 if len(patient_queue) == 0: print("当前没有病人排队。") else: print("当前排队病人的就诊号为:") for visit_number in patient_queue: print(visit_number) elif choice == "5": # 下班 print("医生下班了。") break else: print("输入有误,请重新选择操作。") ``` 运行上述代码,即可在命令行界面上进行就医管理。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值