UVA online 11459_SnakeAndLadders

coding cpp uvaonline

The problem was pretty easy, but there was a trap in the question. It was poorly worded and led to much confusion on the part of the programmers. It was not clearly stated if the process of changing the value takes place before or after the dice roll, which led to WA the first time i tried it.

#include <cstdio>
#include <map>
using namespace std;

int main(){
    char line[1024]; gets(line);
    int n; sscanf(line, "%d", &n);
    while(n--){
        int np, nc, nr, end=0; gets(line);
        sscanf(line, "%d %d %d", &np, &nc, &nr);

        int ps[np];
        for(int p=0; p<np; p++){ ps[p]=1; }
        map<int, int> cs;

        for(int i=0; i<nc; i++){
            gets(line); 
            int a, b; sscanf(line, "%d %d", &a, &b);
            cs[a] = b;
        }

        for(int i=0; i<nr; i++){
             gets(line);
             int r; sscanf(line, "%d", &r);
             int p=i%np;

             if(!end){
                 ps[p] += r;
                 if(ps[p]>100){ ps[p] = 100; }
                 while(cs[ps[p]]){ ps[p] = cs[ps[p]]; }

                 if(ps[p]==100){ end=1; }
            }
        }

        for(int p=0; p<np; p++){
            printf("Position of player %d is %d.\n", p+1, ps[p]);
        }
    }
}