Rating changes for the last round are temporarily rolled back. They will be returned soon. ×

trouble with uvalive 6802

Revision en1, by zarif_2002, 2018-12-10 10:56:04

please tell me why they show me wrong answer.

here

i used this technique. if a = 1, go right. if a = -1, go left, if b = 1, go up, if b = -1, go down.

used ara[64][64] to store 0 if it is not travelled and store 1 if it is travelled.

include<stdio.h>

include<string.h>

int main(){

int a,b,i,j,m,n,t,len,ara[64][64],p,q,r;

char s[130];

scanf("%d",&t);

for(i = 0; i < t; i++){

    scanf("%d %d\n", &m, &n);

    r = 0;

    gets(s);

    for(p = 0; p < 64; p++){

        for(q = 0; q < 64; q++){

            ara[p][q] = 0;
        }
    }
    ara[m][n] = 1;

    len = strlen(s);

    a = 0, b = 1;

    for(j = 0; j < len; j++){

        if(s[j] == 'F'){

            if(b == 1){

                n++;
            }
            else if(b == -1){

                n--;
            }
            else if(a == 1){

                m++;
            }
            else if(a == -1){

                m--;
            }
            if(ara[m][n] == 1){

                r++;
            }
            else{

                ara[m][n] = 1;
            }
        }
        else if(s[j] == 'R'){

            if(b == 1){

                b = 0;

                a = 1;
            }
            else if(b == -1){

                b = 0;

                a = -1;
            }
            else if(a == 1){

                a = 0;

                b = -1;
            }
            else if(a == -1){

                a = 0;

                b = 1;
            }
        }
        else{

            if(a == 1){

                a = 0;

                b = 1;
            }
            else if(a == -1){

                a = 0;

                b = -1;
            }
            else if(b == 1){

                b = 0;

                a = -1;
            }
            else if(b == -1){

                b = 0;

                a = 1;
            }
        }
    }
    printf("%d %d %d\n",m,n,r);
}
return 0;

}

Tags #uva

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English zarif_2002 2018-12-10 10:58:18 16 Tiny change: ' printf("%d %d %d\n",m,n,r);\n' -> ' printf("Case #%d: %d %d %d\n",i + 1,m,n,r);\n'
en1 English zarif_2002 2018-12-10 10:56:04 2495 Initial revision (published)