U E D R , A S I H C RSS

Euclid's Game/강소현

Status

Problem2348Usertalin0528
Memory3516KTime297MS
LanguageJavaResultAccepted

Source

import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextInt()){
			int r1 = sc.nextInt();
			int r2 = sc.nextInt();
			if(r1==0 && r2==0)
				break;
			playGame(r1,r2);
		}
	}
	private static void playGame(int r1, int r2) {	
		int g, r, count=0;
		while(r1%r2!=0){
			g = r1/r2;
			if(g>1) break;
			if(r1>=r2) count++;
			r = r1-g*r2;
			r1 = r2;
			r2 = r;
		}
		if(count%2 == 1){
			System.out.println("Ollie wins");
		}else{
			System.out.println("Stan wins");
		}
	}
}

Trial and Error

  • 왜 중간단계로 11 7ì�´ 나오는 ì§€ ì�´í•´ê°€ 안 갔었다. 베스킨ë�¼ë¹ˆìФ31 게임처럼 숫ìž�를 ìž�유롭게 부르ë�˜ ì�´ê¸°ë ¤ë©´ 절대ì �으로 불러야하는 숫ìž�ê°€ 있는 것처럼, ì�´ 것ë�„ 처ì�Œ 시작하는 사람ì�´ ì�´ê¸°ë ¤ê³  ì�¼ë¶€ëŸ¬ ë�œ 뺀 거였다 ã„·ã„·

    25 7

    11 7

    4 7

    4 3

    1 3

    1 0

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:14
Processing time 0.0037 sec