카테고리 없음
라이브 코딩테스트
father6019
2025. 5. 15. 22:25
728x90
반응형
조만간 라이브코테를 봐야한다..
한번도 안해본거라..
코테 극혐..
어떤 고마우신 분의 후기를 보니 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로 출력
*/
이게 조건인듯..
다시 만들어 보잣
728x90
반응형