СД
Сергей Дорофеев

Array walker C language.

Всем привет. Имеется такое задание:
Array Walker Write a program that computes a ”walk” (of a cute robot) across a 10x10 array. The array contains characters (all initially ’.’). The user can enter four different directions north, east, south, west, by entering the characters n,e,s,w to control the walk. If the user enters x the program exits. After each direction-command the array is printed with the walk being display by capital letter starting with A to Z. We use A for the starting point, with 25 remaining letters to denote the steps. After having used letter Z to denote a step, we wrap around and start again with A. To make the walk more interesting, the user is not allowed to revisit a location. In this case the program does not print the array, but prints ”You cannot go there!” - Yes, you can trap yourself. Starting in the upper left corner (position 0,0):

Вот что я уже сделал.

#include #include
#define M 26
#define N 10
#define K 10


int main()
{
char A[N][K],direction;
char let[M] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char start='A';
int x=0,y=0;
int i=0,j=0,m,k;


for(i=0; i for(j=0; j A[i][j]='.';}


for(i=0; i A[0][0]=let[0];
for(j=0; j printf("%c",A[i][j]);
printf("\n");
}


k=0;
A[x][y]=let[k];


printf("enter direction:\n");
scanf("%c",&direction);
do{


if (direction == 's' && x==10 || direction=='e' && y==10 || direction=='w' && y==0 || direction=='n' && x==0){
printf("u cant go there\n");
for(i=0; i for(j=0; j printf("%c",A[i][j]);
printf("\n");}

}else if(direction=='s') {
x++;
k++;
A[x][y]=let[k];
for(i=0; i for(j=0; j printf("%c",A[i][j]);
printf("\n");}


}else if (direction=='e'){
y++;
k++;
A[x][y]=let[k];
for(i=0; i for(j=0; j printf("%c",A[i][j]);
printf("\n");}


}else if (direction=='w'){
y--;
k++;
A[x][y]=let[k];
for(i=0; i for(j=0; j printf("%c",A[i][j]);
printf("\n");}


}else if (direction=='n'){
x--;
k++;
A[x][y]=let[k];
for(i=0; i for(j=0; j printf("%c",A[i][j]);
printf("\n");}
}
printf("enter direction:\n");
scanf("%c",&direction);
} while (k!=26);
}

проблема такая. Почему-то после запроса одной команды, в следующий раз текс 'enter direction' отображается 2 раза.

проблема вторая. я так понимаю что условие для того, чтобы не возвращаться на уже посещенную позицию должно выглядеть как A[x++][y]!='.'(например для юга) . если я понял правильно, как мне это реализовать, куда мне впихнуть это условие? Прошу прощения, может звучит глупо, но я правда не понимаю этот момент.

Похожие вопросы
Array (['name'] => имя ['surname'] => фамилия) превратить в Array ([1] => имя [2] => фамилия)
Подскажите как исправить данную ошибку в ПАВНО>> array sizes do not match, or destination array is too small ...
напищите пожалйста программу var A: array [1..4,1..5] of integer; b: array [1..4] of boolean; По массиву A получит
Помогите пожалуйста написать головную программу для class Array C++
Что такое Randomize и что такое array[1..15] of shortint
В C++ массив объявляется к примеру int/char array[число элементов] ; а если я не знаю сколько элементов будет?
Вопрос по C++ array vs vector и что это: ^>^?
Какие действия выполняет оператор array? P
Russian language
Visual Studio 2013 Ultimate (Language pack RU)