일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- Python
- 차트
- analyzer test
- high level client
- plugin
- Java
- licence delete curl
- license delete
- TensorFlow
- 900gle
- zip 파일 암호화
- docker
- Kafka
- aggs
- zip 암호화
- aggregation
- Test
- flask
- token filter test
- API
- sort
- query
- License
- Elasticsearch
- MySQL
- matplotlib
- Mac
- 파이썬
- ELASTIC
- springboot
Archives
- Today
- Total
개발잡부
라이브 코딩테스트 본문
반응형
조만간 라이브코테를 봐야한다..
한번도 안해본거라..
코테 극혐..
어떤 고마우신 분의 후기를 보니 3,6,9 게임에 여러가지 부가 기능을 추가 하는 것 같은데.. 일단 글에 나와 있는 조건을 구현해 보았다.
1단계 : 주어진 요구사항에 맞게 369 게임
구현2단계 : 오답률에 따른 게임 종료 및 사용자 등 몇 가지 심화 기능과 클래스
추가3단계 : 지역별 다른 규칙의 369 게임을 위해 추상화 및 다형성
적용4단계 : 다양한 지역 동시 게임 진행을 위한 동시성 적용
출처: https://kang-james.tistory.com/entry/회고-라이브-코딩-면접-후기 [내 꿈을 JAVA:티스토리]
이조건들을 순서대로 알려주는건가.. 일단 위의 조건대로 구현을 해봤는데.. 이게 맞나.. 뭔가.. 찝찝한데
package kr.co.homeplus.livetwo;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicInteger;
abstract class User {
public abstract String answer(String action, int errRate);
protected int rate(){
return (int) (Math.random() * 100) + 1;
}
}
class Player extends User {
@Override
public String answer(String action, int errRate){
if(rate() < errRate) {
return "ERROR";
} else {
return action;
}
}
}
class PlayerFactory implements UserFactoryInterface {
@Override
public User getUser(){
return new Player();
}
}
class UserFactory {
public static User getUser (UserFactoryInterface userFactoryInterface){
return userFactoryInterface.getUser();
}
}
interface UserFactoryInterface {
public User getUser();
}
abstract class Game {
public abstract String play(int number);
}
class GameFactory {
public static Game getGame(GameFactoryInterface gameFactoryInterface) {
return gameFactoryInterface.getGame();
}
}
interface GameFactoryInterface {
public Game getGame();
}
class SeoulTSNGame extends Game {
@Override
public String play(int number) {
char[] chars = String.valueOf(number).toCharArray();
StringBuffer stringBuffer = new StringBuffer();
for (char c : chars) {
if (c == '3' || c == '6' || c == '9') {
stringBuffer.append("짝");
}
}
if (stringBuffer.length() < 1) {
return String.valueOf(number);
} else {
return stringBuffer.toString();
}
}
}
class BusanTSNGameFactory implements GameFactoryInterface {
@Override
public Game getGame() {
return new SeoulTSNGame();
}
}
class BusanTSNGame extends Game {
@Override
public String play(int number) {
char[] chars = String.valueOf(number).toCharArray();
StringBuffer stringBuffer = new StringBuffer();
for (char c : chars) {
if (c == '3' || c == '6' || c == '9') {
stringBuffer.append("Clap");
}
}
if (stringBuffer.length() < 1) {
return String.valueOf(number);
} else {
return stringBuffer.toString();
}
}
}
class SeoulTSNGameFactory implements GameFactoryInterface {
@Override
public Game getGame() {
return new SeoulTSNGame();
}
}
public class GameTestTwoMain {
public static void main(String[] args) {
Game seoulGame = GameFactory.getGame(new SeoulTSNGameFactory());
Game busanGame = GameFactory.getGame(new BusanTSNGameFactory());
User user = UserFactory.getUser(new PlayerFactory());
int n = 100;
AtomicInteger clapCout = new AtomicInteger(0);
CompletableFuture<Void> seoulTask = CompletableFuture.runAsync(()->{
for (int i = 1; i < n + 1; i++) {
if(seoulGame.play(i).equals(user.answer(seoulGame.play(i), 30))){
char[] chars = String.valueOf(i).toCharArray();
for (char c : chars) {
if (c == '3' || c == '6' || c == '9') {
clapCout.incrementAndGet();
}
}
System.out.println(seoulGame.play(i));
} else {
System.out.println("Seoul Game Over");
break;
}
}
});
CompletableFuture<Void> busanTask = CompletableFuture.runAsync(()->{
for (int i = 1; i < n + 1; i++) {
if(busanGame.play(i).equals(user.answer(busanGame.play(i), 0))){
char[] chars = String.valueOf(i).toCharArray();
for (char c : chars) {
if (c == '3' || c == '6' || c == '9') {
clapCout.incrementAndGet();
}
}
System.out.println(busanGame.play(i));
} else {
System.out.println("Busan Game Over");
break;
}
}
});
CompletableFuture.allOf(seoulTask, busanTask).join();
System.out.println("totalClapCount: "+ clapCout);
}
}
음.. 일단 이렇게 구현.. 했는데..
조건이 더 있었네.. 망..
아 코테 보지 말까..
/**
* 1) 게임횟수만큼 순회 (100회)
* 2) 초기 시작 숫자 : 1
* 3) 현재 숫자 do369메서드 인자로 사용
* 4) do369 - 숫자를 문자열로 변경
* 5) do369 - 문자열에서 3, 6, 9 라는 숫자를 갖는지 체크
* 6) ㄴ 있으면 clap 반환, 없으면 숫자 문자형태로 반환
* 7) 현재 숫자를 말할 사용자 선택
* 8) (현재 숫자-1 % 4) => players 인덱스
* 9) do369의 결과와 인덱스에 해당하는 players를 sout로 출력
*/
이게 조건인듯..
다시 만들어 보잣
반응형
'이직' 카테고리의 다른 글
코테준비 (0) | 2025.05.14 |
---|---|
[groom] 구름이의 취미 (0) | 2023.05.13 |
[programmers] 같은 숫자는 싫어 (0) | 2022.08.28 |
[codility] Dominator (0) | 2022.08.08 |
TwoSum (0) | 2022.07.27 |
Comments