๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm/Etc

์ž๋ฐ” ๋ฐฐ์—ด ๋ฌด๊ถํ™”๊ฝƒ ๋ฌธ์ œ

by yunamom 2022. 1. 21.
728x90
300x250
package G3_๋ฐฐ์—ด์‹ฌํ™”3_ํ‰๊ฐ€๋ฌธ์ œ;

import java.util.Arrays;
import java.util.Random;

/*
	[์˜ค์ง•์–ด๊ฒŒ์ž„]
	
	[๋ฌด๊ถํ™” ๊ฝƒ์ด ํ”ผ์—ˆ์Šต๋‹ˆ๋‹ค]
	doll ์€ ์ธํ˜•์ด๊ณ  , arr ์€ ์˜ค์ง•์–ด ๊ฒŒ์ž„ ์ฐธ๊ฐ€์ž๋“ค ์ด๋‹ค. 	
	[1] ๊ฒŒ์ž„์€ 10ํšŒ ๋ฐ˜๋ณต๋œ๋‹ค. 
	[2] doll ๋งคํ„ด ๋งˆ๋‹ค 3~5๋ฅผ ๋žœ๋ค์œผ๋กœ ์ €์žฅํ•œ๋‹ค.
	[3] arr ์€ ๋žœ๋ค์œผ๋กœ 1~4๋ฅผ ์ €์žฅํ•œ๋‹ค. 
	[4] ๋งคํ„ด๋งˆ๋‹ค doll ๋ณด๋‹ค ํฐ์ˆซ์ž๊ฐ€ ๋‚˜์˜จ ์ฐธ๊ฐ€์ž๋Š” ์›€์ง์ธ๊ฒƒ์œผ๋กœ ๊ฐ„์ฃผ๋˜์–ด ํƒˆ๋ฝ๋œ๋‹ค.
	[5] 10ํšŒ ๊นŒ์ง€ ์‚ด์•„๋‚จ์€ ์ฐธ๊ฐ€์ž์˜ ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค.
	[6] 1๋“ฑ์˜ ๋ฒˆํ˜ธ๋ฅผ ์ถœ๋ ฅํ•˜์‹œ์˜ค.
	
	
 */
class Flower_Game{
	Random ran = new Random();
	
	int arr[]=new int[10]; boolean check[]=new boolean[10];
	int survivor[]=new int[10];
	int doll; int cnt=0; int win=0;
	void flower_Winner() {
		int max=0;
		for(int i=0; i<check.length; i++) {
			if(check[i]==false) {
				if(max < survivor[i]) {
					max = survivor[i]; win=i;
				}
			}
		}
		System.out.println(win+"๋ฒˆ ์ฐธ๊ฐ€์ž ์šฐ์Šน!");
	}
	void flower_Check() {
		for(int i=0; i<check.length; i++) {
			if(check[i]==false) {
				System.out.println(i+"๋ฒˆ ์ƒ์กด!"+survivor[i]);				
			}
		}
	}
	void flower_Start() {
		doll=ran.nextInt(3)+3;
		for(int i=0; i<arr.length; i++) {
			arr[i] = ran.nextInt(4)+1;
			if(check[i]==false) {
				if(doll<arr[i]) {
					check[i] = true;
					System.out.println(i+"๋ฒˆ ํƒˆ๋ฝ!");	
				}else {
					survivor[i]+=arr[i];
				}
			}
		}
	}
	void run() {
		while(cnt<10) {
			System.out.println("--------------------");
			System.out.println(cnt+1+")ํšŒ ");
			System.out.println("๋ฌด๊ถํ™”๊ฝƒ์ด ํ”ผ์—ˆ์Šต๋‹ˆ๋‹ค.");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			flower_Start();
			System.out.println("๋ฒˆํ˜ธ:"+doll);
			cnt++;
		}
		flower_Check(); //์ƒ์กด์ž
		System.out.println("---------------------");
		flower_Winner();
	}
}
public class ๋ฐฐ์—ด์‹ฌํ™”3_๋ฌด๊ถํ™”๊ฝƒ_์—ฐ์Šต {
	public static void main(String[] args) {
		
		Flower_Game go = new Flower_Game();
		go.run();
	}
}

 

728x90
300x250

์ฝ”๋“œ