[java]代码库
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
BookList bl = new BookList();
int n = s.nextInt();
for (int i=0; i<n;i++) {
bl.addBook(new Book(s.next(),s.nextInt(),s.next(),s.nextInt()));
}
bl.searchBook(new Book(s.next(),0,s.next(),s.nextInt()));
}
}
class Book{
String name;
int price;
String author;
int number;
public Book(String na, String au, int num) {
name = na;
author = au;
number = num;
}
public Book(String na, int p, String au, int num) {
name = na;
price = p;
author = au;
number = num;
}
public String getName() {
return name;
}
public String getAuthor() {
return author;
}
public int getNumber() {
return number;
}
}
class BookList{
List<Book> L = new LinkedList<Book>();
public void addBook(Book b) {
L.add(b);
}
public void searchBook(Book b) {
int i, flag = 0;
for(i = 0; i < L.size(); i++) {
if(L.get(i).getName().equals(b.getName()) && L.get(i).getAuthor().equals(b.getAuthor()) && L.get(i).getNumber()==b.getNumber()) {
flag = 1;
System.out.println("found: " +i);
}
}
if(flag == 0)
System.out.println("not found");
}
}