#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<vector>
#include<iterator>
using namespace std;
struct zhi
{
char name[10];
int num;
}p[10];
void shuru()
{
int i;
for(i=0; i<10; i++){
cout << "input NO." ;
cin >> p[i].num;
getchar();
cout << "input name:" ;
gets(p[i].name);
}
}
bool cmp(zhi a, zhi b)
{
if(a.num!=b.num) return a.num < b.num;
}
void zhe(int n)
{
int top=9, bott=0, mid, sign=1, loca=0;
if((n<p[0].num)||(n>p[9].num))
loca=-1;
while(sign==1 && bott<=top)
{
mid=(bott+top)/2;
if(n==p[mid].num){
loca=mid;
// cout << loca << endl;
cout << "NO." << p[loca].num << " " << p[loca].name << endl;
sign=-1;
}
else if(n<p[mid].num){
top=mid-1;
}
else
bott=mid+1;
}
if(sign==1||loca==-1)
cout << n << " not been found." << endl;
}
int main()
{
int flag=1,i,n;
char c;
shuru();
sort(p, p+10, cmp);
for(i=0; i<10; i++){
cout << p[i].num << " " << p[i].name << endl;
}
while(flag == 1)
{
cout << "输入一个职工号:" ;
cin >> n;
zhe(n);
cout << "continue or not(Y/N)?" << endl;
getchar();
c=getchar();
if(c=='N'||c=='n')
flag=0;
}
return 0;
}
经常犯低级错误。。。无奈