Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |
Tags
- 알고리즘
- SWEA
- 문자열
- db
- 건강
- BOJ
- 이분탐색
- 러닝일지
- 자바
- 투포인터
- 코딩테스트
- Java
- BFS
- 코테
- math
- 시뮬레이션
- 백준
- SQL
- greedy
- dfs
- COS PRO
- 문제풀이
- 프로그래머스
- priorityqueue
- 운동기록
- DP
- MySQL
- oracle
- binary search
- 문제해결
Archives
- Today
- Total
슈콩
COS PRO 1급 밥먹고 머리자르고 본문





[소스 코드]
import java.util.ArrayList;
import java.util.Iterator;
class Main {
class Shop{
protected ArrayList<Customer> reserveList;
public Shop() {
this.reserveList = new ArrayList<Customer>();
}
public boolean reserve(Customer customer){
reserveList.add(customer);
return true;
}
}
class Customer{
public int id;
public int time;
public int numOfPeople;
public Customer(int id, int time, int numOfPeople){
this.id = id;
this.time = time;
this.numOfPeople = numOfPeople;
}
}
class HairShop extends Shop {
public HairShop(){
super();
}
public boolean reserve(Customer customer) {
if(customer.numOfPeople != 1)
return false;
Iterator<Customer> iter = reserveList.iterator();
while (iter.hasNext()) {
Customer r = iter.next();
if(r.time==customer.time)
return false;
}
reserveList.add(customer);
return true;
}
}
class Restaurant extends Shop {
public Restaurant(){
super();
}
public boolean reserve(Customer customer){
if(customer.numOfPeople<2 || customer.numOfPeople>8)
return false;
int count = 0;
Iterator<Customer> iter = reserveList.iterator();
while (iter.hasNext()) {
Customer r = iter.next();
if(r.time==customer.time)
count += 1;
}
if(count >= 2)
return false;
reserveList.add(customer);
return true;
}
}
public int solution(int[][] customers, String[] shops) {
Shop hairshop = new HairShop();
Shop restaurant = new Restaurant();
int count = 0;
for(int i = 0; i < shops.length; i++){
if(shops[i].equals("hairshop")){
if(hairshop.reserve(new Customer(customers[i][0], customers[i][1], customers[i][2])))
count += 1;
}
else if(shops[i].equals("restaurant")){
if(restaurant.reserve(new Customer(customers[i][0], customers[i][1], customers[i][2])))
count += 1;
}
}
return count;
}
}
상속 : extends -> override 가능 , 단일 상속만 가능
인터페이스 구현 : implements -> 추상 메서드 정의