Uva230
来源:互联网 发布:天池大数据竞赛官网 编辑:程序博客网 时间:2024/04/30 06:23
package test;import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.Random;import java.util.Scanner;public class Test{ static class Book{ String author; String title; public Book(String author, String title) { super(); this.author = author; this.title = title; } @Override public String toString() { return author+":"+title; } } static int n = 5; static ArrayList<Book> shelf = new ArrayList<Book>(); static ArrayList<Book> pile = new ArrayList<Book>(); static ArrayList<Book> borrow = new ArrayList<Book>(); public static void main(String[] args) { shelf.add(new Book("adfas","sadasds")); shelf.add(new Book("weraw","ngfh")); shelf.add(new Book("weraw","nghh")); shelf.add(new Book("werew","ngfh")); shelf.add(new Book("gfdsa","bxcvxc")); shelf.add(new Book("weweq","qqqe")); shelf.add(new Book("poii","wewr")); Scanner scanner = new Scanner(System.in); String com = null; Random r = new Random(); Comparator<Book> comparator = new Comparator<Book>() { @Override public int compare(Book o1, Book o2) { if(o1.author.compareToIgnoreCase(o2.author)>0){ return 1; }else if((o1.author.compareToIgnoreCase(o2.author)<0)){ return -1; }else{ if((o1.title.compareToIgnoreCase(o2.title)>0)){ return 1; }else if(o1.title.compareToIgnoreCase(o2.title)<0){ return -1; } } return 0; } }; Collections.sort(shelf,comparator); System.out.println("书架:"+shelf); System.out.println("借出:"+borrow); System.out.println("归还:"+pile); while(!"END".equals(com=scanner.nextLine())){ if(com.startsWith("B")){ if(shelf.size()>0){ borrow.add(shelf.remove((r.nextInt(shelf.size())))); System.out.println("书架:"+shelf); System.out.println("借出:"+borrow); System.out.println("归还:"+pile); } }else if(com.startsWith("R")){ if(borrow.size()>0){ pile.add(borrow.remove((r.nextInt(borrow.size())))); System.out.println("书架:"+shelf); System.out.println("借出"+borrow); System.out.println("归还"+pile); } }else if(com.startsWith("S")){ if(pile.size()>0){ Collections.sort(pile,comparator); int i=0; for(;i<shelf.size();i++){ if(pile.get(0).author.compareTo(shelf.get(i).author)<0 && pile.get(0).title.compareTo(shelf.get(i).title)<0){ shelf.addAll(i, pile); break; } } if(i==shelf.size()){ shelf.addAll(pile); } pile.clear(); System.out.println("书架:"+shelf); System.out.println("借出:"+borrow); System.out.println("归还:"+pile); } } } scanner.close(); } }
0 0
- Uva230
- UVa230
- UVa230 - Borrowers
- UVA230 - Borrowers
- UVA230 Borrowers
- UVa230 Borrowers
- uva230-Borrowers
- UVA230-图书馆管理
- UVA230解题报告
- 刷题打卡3 UVa230
- 习题5-8 图书管理系统 UVa230
- 习题5-8 图书管理系统(Borrowers, UVa230)
- 关于”图书管理系统(Borrowers,ACM/ICPC World Finals 1994, UVa230)"的讨论
- [刷题]算法竞赛入门经典(第2版) 5-8/UVa230 - Borrowers
- 算法竞赛入门经典 第二版 习题5-8 图书管理系统 Borrowers uva230
- Android中字体颜色大全-146种(完整版)
- [LeetCode]127.Word Ladder
- poj 2528 Mayor's posters 简单离散化+线段树
- 腾讯游戏数据自愈服务方案
- TCP 握手挥手详解
- Uva230
- UIKit基础:1.第一个UIKit程序
- C51回顾五
- 基于boost asio实现的支持ssl的通用socket框架
- lua学习笔记16:table元表详解
- 2014年国人开发的最热门的开源软件TOP 100
- 将LFS系统通过grub装到优盘上启动
- Linux下安装和使用RTX腾讯通
- 生产服务器环境最小化安装后 Centos 6.5优化配置备忘