输入:
8
9787302257646 Data-Structure 35.00
9787302164340 Operating-System 50.00
9787302219972 Software-Engineer 32.00
9787302203513 Database-Principles 36.00
9787810827430 Discrete-Mathematics 36.00
9787302257800 Data-Structure 62.00
9787811234923 Compiler-Principles 62.00
9787822234110 The-C-Programming-Language 38.00
2
2
0
输出:
9787302164340 Operating-System 50.00
Sorry,the book on the best position doesn't exist!
代码:
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
#define OK 1
#define error 0
#define Maxsize 1000
typedef struct
{
string IBNS;
string NAME;
float PRICE;
}Book;
typedef struct
{
Book* elem;
int length;
}List;
int InitList_L(List& L);
int InsertList_L(List& L);
int FindList_L(List L);
int main()
{
List L;
InitList_L(L);
InsertList_L(L);
FindList_L(L);
return 0;
}
int InitList_L(List& L)
{
L.elem = new Book[Maxsize];
if (!L.elem) exit(0);
L.length = 0;;
return OK;
}
int InsertList_L(List& L)
{
int num;
cin >> num;
for (int i = 0; i < num; i++)
{
cin >> L.elem[i].IBNS >> L.elem[i].NAME >> L.elem[i].PRICE;
L.length++;
}
return OK;
}
int FindList_L(List L)
{
int num;
cin >> num;
for (int i = 0; i < num; i++)
{
int num1;
cin >> num1;
if (num1 > 0 && num1 < L.length)
cout << L.elem[num1-1].IBNS << " " << L.elem[num1-1].NAME << " " << fixed << setprecision(2) << L.elem[num1-1].PRICE << endl;
else
cout << "Sorry,the book on the best position doesn't exist!" << endl;
}
return OK;
}