# UVA 11459 – Snakes and Ladders

Simple simulation game. Don’t forget to read through the entire input if the game ends early! That cost me a couple of tries :[

```import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
*
* @author Sanchit M. Bhatnagar
* @see http://uhunt.felix-halim.net/id/74004
*
*/
public class P11459 {

public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);

int cases = sc.nextInt();
while (cases > 0) {
int players = sc.nextInt();
int cheats = sc.nextInt();
int rolls = sc.nextInt();

int[] map = new int;
for (int i = 0; i < cheats; i++) {
map[sc.nextInt()] = sc.nextInt();
}

int playerIdx = 0;
int[] pos = new int[players];
Arrays.fill(pos, 1);
for (int i = 0; i < rolls; i++) {
pos[playerIdx] += sc.nextInt();
if (map[pos[playerIdx]] != 0)
pos[playerIdx] = map[pos[playerIdx]];
if (pos[playerIdx] >= 100) {
pos[playerIdx] = 100;
while (i + 1 < rolls) {
sc.nextInt();
i++;
}
break;
}
playerIdx++;
if (playerIdx == players)
playerIdx = 0;
}
for (int i = 0; i < players; i++) {
out.println("Position of player " + (i + 1) + " is " + pos[i] + ".");
}
cases--;
}

out.close();
sc.close();
}
}
```

## 5 thoughts on “UVA 11459 – Snakes and Ladders”

1. Ayat Khrisat says:

hi my code look same like you except i used hashMap nested of array map but uva give me RunTime error do you why?

2. Rawrosaur says:

3. Ayat Khrisat says:

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
*
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
for(int i=0 ;i<t;i++){
int players=Integer.parseInt(s);
int play[]=new int [players];
for(int j=0 ;j<players;j++){
play[j]=1;}
int snake = Integer.parseInt(s);
int rolls = Integer.parseInt(s);

Map map =new HashMap();
for(int j=0 ;j<snake;j++){

map.put(Integer.parseInt(s1),Integer.parseInt(s1));

}

int x=0;

for(int j=0 ;j=100) { play[x]=100;
while(j+1<rolls){
j++;
} break;}
x++;
if(x==players) x=0;
}

int ii=0;
for(;ii<players;ii++){

System.out.printf("Position of player %d is %d.%n",(ii+1),play[ii]);
}

}
r.close();
}}

4. Rawrosaur says:

Well firstly use something like http://pastebin.com/ to share code so it is easy to read. Secondly it doesn’t seem like your code compiles. It could be a copy paste error, dunno. Can you post your code to pastebin please? This is the code as I see it right now. https://flic.kr/p/xF2Vn2 It does not compile and certain variables are out of scope.

This site uses Akismet to reduce spam. Learn how your comment data is processed.