#include <stdio.h>
#include <string.h>
#define N 5
#define M 30
int flag=1;
main()
{
int num[N],i,j,n;
char name[N][M],none[5]="None";
system("cls");
printf("please input %d employees information./n",N);
for(i=0;i<N;i++)
{
printf("NO.%d: ",i+1);
scanf("%d",&num[i]);
for(;!(num[i]>=0&&num[i]<=32767);)
{
printf("Error! Input again: /a");
scanf("%d",&num[i]);
}
gets(name[i]);
}
system("cls");
printf("All information:/n");
for(i=0;i<N;i++)
printf("No.%d: employee:%s, Number:%d/n",i+1,(name[i][0]=='')?none:name[i],num[i]);
puts('');
than(num,name);
printf("Input will search number: ");
scanf("%d",&n);
j=search(num,n);
if(!flag) printf("Can't find %d, search is not found./n",n);
else printf("'%d' position is %d, name is %s./n",n,j+1,name[j]);
}
than(int str[],char st[][M]) /*自定义函数than的功能是按员工编号的先后顺序(升序)重新对员工的信息(含员工姓名)进行排列*/
{
int i,j,max;
char temp[M];
for(i=0;i<N-1;i++)
for(j=i+1;j<N;j++)
if(str[i]>str[j])
{
max=str[i];
str[i]=str[j];
str[j]=max;
strcpy(temp,st[i]);
strcpy(st[i],st[j]);
strcpy(st[j],temp);
}
for(i=0;i<N;i++)
printf("Now:%d, %s/n",str[i],st[i]);
}
int search(int str[],int n) /*自定义函数search的功能是搜索我们想要查找的员工编号*/
{
int i,j=N-1,flag;
if(n<str[0]||n>str[j]) flag=0;
else
{
for(i=0;i<N;i++)
{
if(n!=str[i]);
else j=i;
}
}
return j;
}