Solution for CCC '03 S1 - Snakes and Ladders in Java 8


Feb. 7, 2020 0.475570 seconds Java 8
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String args[]) {
		
		Scanner in = new Scanner(System.in);
		int rolled;
		int position = 1;
		
		do {
			rolled = in.nextInt();
			if(rolled == 0){
				System.out.println("You Quit!");
				break;
			}
			
			if(position + rolled <= 100) {
				position += rolled;
			}
			position = snakeCheck(position);
		
			if(position >= 100) {
				System.out.println("You are now on square " + 100);
				System.out.println("You Win!");
				break;
			}else {
				System.out.println("You are now on square " + position);
			}
			
			
			
		}while(rolled != 0);
		return;
	}
	
	public static int snakeCheck(int pos) {
		
		switch(pos) {
		
		case(9):
			return 34;
		
		case(40):
			return 64;
		
		case(54):
			return 19;
		
		case(67):
			return 86;
		
		case(90):
			return 48;
		
		case(99):
			return 77;
		
		
		}
		
		return pos;
	}
	
}

Editorial


No editorial for this problem. :(

Original Problem


You can view the original page for this problem on the DMOJ.