Home | Web Board | ProblemSet | Standing | Status | Statistics |
Problem E: 图书管理系统
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1060 Solved: 399
[ Submit][ Status][ Web Board]
Description
图书馆里面有若干本书(至少3000本,至多30000本),为帮助用户快速查找每本书所在的书架位置,请设计一个模拟系统实现基于图书编号的快速查询方法。
Input
多组数据,每组数据第一行为一个整数n代表图书的数目,接下来n行,每行输入两个字符串id、s和两个整数r、c,代表图书的ISBN码、图书的名称、图书所在的排和列。第n+2行输入一个整数q代表查询的个数,接下来输入q行查询,每个查询输入为图书的ISBN编码。
Output
对于每个查询输出图书名,排号和列号。
Sample Input
2ISBN-978-7-302-35628-8 AOAPC_II 1 1ISBN-978-7-115-37950-4 Data_Structure 1 22ISBN-978-7-115-37950-4ISBN-978-7-302-35628-8
Sample Output
Data_Structure 1 2AOAPC_II 1 1
HINT
禁用STL容器
Append Code
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
/*struct Book
{
char ibsn[25];
char name[20];
int r,c;
};
Book& Search(Book b[30005],char ch[20])
{
for(int i=1;i<=length;i++)
{
if(b[i].ibsn == ch)
return b[i];
}
}
int main()
{
int n,m;
Book book[30005];
char ch[25];
length=0;
while(~scanf("%d",&n))
{
for(int i=1;i<=n;i++)
{
scanf("%s %s %d %d",book[i].ibsn,book[i].name,&book[i].r,&book[i].c);
length++;
}
scanf("%d",&m);
for(int i=1;i<=m;i++)
{
Book b;
scanf("%s",ch);
b = Search(book,ch);
printf("%s %d %d\n",b.name,b.r,b.c);
}
}
}
*/
struct B
{
string isbn;
string name;
int r,c;
};
struct Book
{
B r[30005];
int length ;
};
int Search(Book &book,string ch)
{
int low = 1,high = book.length;
while(low<=high)
{
int mid = (low+high)/2;
if(book.r[mid].isbn==ch)
return mid;
if(ch<book.r[mid].isbn)
high = mid - 1;
else
low = mid + 1;
}
return 0;
}
int com(B a,B b)
{
return a.isbn<b.isbn;
}
int main()
{
int n,m;
Book book;
book.length=0;
while(cin>>n)
{
for(int i=1;i<=n;i++)
{
cin>>book.r[i].isbn>>book.r[i].name>>book.r[i].r>>book.r[i].c;
book.length++;
}
sort(book.r+1,book.r+book.length+1,com);
cin>>m;
for(int i=1;i<=m;i++)
{
int a = 0;
string ch;
cin>>ch;
a = Search(book,ch);
cout<<book.r[a].name<<" "<<book.r[a].r<<" "<<book.r[a].c<<endl;
}
}
}