十个职工的姓名,职工号
/*输入十个职工的姓名,职工号。按职工号大小顺序输出,姓名也随着调整。
要求输入一职工号,折半查找,从主函
数输入要查找的职工号,输出该职工的姓名。*/
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,temp;int key;
int p=0; char staffList[10];
//char string[]
char staffList[10]={{"刘翔","201003020076"},
{"姚明","20100302001"},
{"宋健","201003020077"},
{"宋丹丹","201003020054"},
{"马大文","201003020090"},
{"孙二林","201003020017"},
{"王三","201003020012"},
{"段五","201003020040"},
{"小六","201003020080"},
{"李四",201003020069"}};
for(i=0;i<10;i++)
scanf("staff=%lf\n",staffList[i]);
for(j=0;j<10;j++)
for(i=j;i<9-j;i++)
if(staffList[i]>staffList[i+1]){
temp=staffList[i];
staffList[i]=staffList[i+1];
staffList[i+1]=temp;
}
for(i=0;i<10;i++)
printf("从小到大输出%f\n",staffList[i]);
while(p==0){
printf("input a staff's number:\n");//折半查找???
scanf("%lf",&key);
if(key==staffList[i])
{
printf("%f ",staffList[i]);
p=1;
}
else{
}
if(p==0)
printf("输入有误,重新出入!\n");
}
return 0;
}
//数组有误总改不对!求大神。。。