#include <iostream> #include <string> //#include <algorithm> using namespace std; class Exam{ public: string num; int disease[100]; int count; Exam(){}; friend void print(Exam*e, int count, int *d); }e[3000]; void print(Exam*e, int count, int *d){ int i=0,j=0,k=0; for(i=0;i<e->count;i++){ while(e->disease[j]!=0){ while(d[k]!=0){ if(e->disease[j]==d[k]){ cout<<e->num<<' '<<d[k]<<endl; return; } k++; } j++; k=0; } j=0; } } void sort(int*a,int b){ int i,j,t; for(i=0;i<b;i++){ for(j=0;j<b-1-i;j++){ if(a[j]>a[j+1]){ t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } } int main (){ int i=0,j=0,m=0; while(1){ cin>>e[i].num; if(e[i].num=="0"){ break; } cin>>e[i].count; for(j=0;j<e[i].count;j++){ cin>>e[i].disease[j]; j++; } i++; } int notice[100]; j=0; while(1){ cin>>notice[j]; if(notice[j]==0){ break; } j++; } sort(notice,j); m=i; for(i=0;i<m;i++){ print(&e[i],e[i].count,notice); } }
时间: 2023-07-15 19:13:13 浏览: 40
这段代码实现了一个简单的医学诊断系统。用户输入一些病历信息,包括病人编号、患病数量和患病编码,然后输入一些疾病编码,程序会检索病历信息,找到患有输入的疾病的病人,并输出病人编号和疾病编码。
代码中定义了一个Exam类,包含病人编号、患病数量和患病编码。还定义了一个print函数,用于查找并输出患有指定疾病的病人信息。sort函数用于对输入的疾病编码进行排序。
在主函数中,程序首先读取一些病历信息,然后读取一些疾病编码。对于每个输入的病历信息,程序调用print函数查找患有输入的疾病的病人信息,并输出结果。
需要注意的一点是,程序中的print函数只会输出第一个匹配的病人信息,如果有多个病人患有输入的疾病,只会输出其中一个。
相关问题
#include <iostream> #include<algorithm> #include<cmath> #include <queue> using namespace std;
#include <iostream>:这是C++标准库中的头文件,用于输入输出流操作,包括cin、cout等。
#include<algorithm>:这是C++标准库中的头文件,用于提供各种算法操作,如排序、查找等。
#include<cmath>:这是C++标准库中的头文件,用于提供数学函数操作,如绝对值、平方根等。
#include <queue>:这是C++标准库中的头文件,用于提供队列操作,包括入队、出队等。
using namespace std;:这是C++的命名空间声明,表示使用std命名空间,可以直接使用std中的函数和对象。
#include <iostream> #include <string> #include <stack> #include <vector> #include <iomanip> using namespace std; 逐行注释以上代码
这是一段C++的程序代码,使用了几个标准库的头文件。以下是逐行的注释:
```
#include <iostream> // 输入输出流库头文件
#include <string> // 字符串库头文件
#include <stack> // 栈库头文件
#include <vector> // 向量库头文件
#include <iomanip> // 格式控制库头文件
using namespace std; // 命名空间
```
这段程序代码导入了五个标准库的头文件,分别是iostream、string、stack、vector、iomanip,它们分别用于处理输入输出、字符串、栈、向量和格式控制。其中iostream是C++中最常用的输入输出流库,string是用于字符串操作的库,stack是用于栈数据结构的库,vector是用于动态数组的库,iomanip是用于格式化输出的库。
最后一行代码使用了命名空间std,这意味着所有的标准库函数和变量都在std命名空间中。如果不使用using namespace std,则需要在使用标准库函数时加上std::前缀。
相关推荐
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)