[java]代码库
import java.util.*;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
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
{
private String name;
private int price;
private String author;
private int no;
public Book(String n, int p , String a, int o)
{
name = n;
price = p;
author = a;
no = o;
}
public String getname()
{
return name;
}
public int getprice()
{
return price;
}
public String getauthor()
{
return author;
}
public int getno()
{
return no;
}
}
class BookList
{
List<Book> slist;
public BookList()
{
slist = new ArrayList<Book>();
}
public void addBook(Book b)
{
slist.add(b);
}
public void searchBook(Book b)
{
int flag = 0;
for( int j = 0; j < slist.size(); j++)
{
if(slist.get(j).getname().equals(b.getname()) && slist.get(j).getauthor().equals(b.getauthor()) && slist.get(j).getno() == b.getno())
{
System.out.print("found: "+j);
flag = 1 ;
}
}
if( flag== 0)
{
System.out.print("not found");
}
}
}