int main() { int N; char c; printf("Исходное направление робота (n,w,s,e): "); scanf("%c",&c); printf("Команда (0,1,-1,2,-2): "); scanf("%d",&N); while (N != 0){ switch (N) { case 1 : break; case -1: switch (c) { case 'n' : c = 's'; break; case 'w' : c = 'e'; break; case 's' : c = 'n'; break; case 'e' : c = 'w'; break; }; break; case 2 : switch (c) { case 'n' : c = 'e'; break; case 'w' : c = 'n'; break; case 's' : c = 'w'; break; case 'e' : c = 's'; break; }; break; case -2: switch (c) { case 'n' : c = 'w'; break; case 'w' : c = 's'; break; case 's' : c = 'e'; break; case 'e' : c = 'n'; break; }; break; } printf("c = %c\n", c); printf("Команда (0,1,-1,2,-2): "); scanf("%d",&N); } return 0; }
Пример: Исходное направление робота (n,w,s,e): n Команда (0,1,-1,2,-2): 2 c = e Команда (0,1,-1,2,-2): 1 c = e Команда (0,1,-1,2,-2): -2 c = n Команда (0,1,-1,2,-2): -1 c = s Команда (0,1,-1,2,-2): 0
var x,y:integer; begin readln (x,y); if (x>0) and (y>0) then writeln ('Точка лежит в первой четверти'); if (x<0) and (y>0) then writeln ('Точка лежит во второй четверти'); if (x<0) and (y<0) then writeln ('Точка лежит в третьей четверти'); if (x>0) and (y<0) then writeln ('Точка лежит в четвертой четверти'); if (x=0) and (y=0) then writeln ('Точка лежит на пересечении осей') else if x=0 then writeln ('Точка лежит на оси ординат') else if y=0 then writeln ('Точка лежит на оси абсцисс'); readln; end.
int main()
{
int N;
char c;
printf("Исходное направление робота (n,w,s,e): ");
scanf("%c",&c);
printf("Команда (0,1,-1,2,-2): ");
scanf("%d",&N);
while (N != 0){
switch (N) {
case 1 : break;
case -1:
switch (c) {
case 'n' : c = 's'; break;
case 'w' : c = 'e'; break;
case 's' : c = 'n'; break;
case 'e' : c = 'w'; break;
};
break;
case 2 :
switch (c) {
case 'n' : c = 'e'; break;
case 'w' : c = 'n'; break;
case 's' : c = 'w'; break;
case 'e' : c = 's'; break;
};
break;
case -2:
switch (c) {
case 'n' : c = 'w'; break;
case 'w' : c = 's'; break;
case 's' : c = 'e'; break;
case 'e' : c = 'n'; break;
};
break;
}
printf("c = %c\n", c);
printf("Команда (0,1,-1,2,-2): ");
scanf("%d",&N);
}
return 0;
}
Пример:
Исходное направление робота (n,w,s,e): n
Команда (0,1,-1,2,-2): 2
c = e
Команда (0,1,-1,2,-2): 1
c = e
Команда (0,1,-1,2,-2): -2
c = n
Команда (0,1,-1,2,-2): -1
c = s
Команда (0,1,-1,2,-2): 0
var x,y:integer;
begin
readln (x,y);
if (x>0) and (y>0) then writeln ('Точка лежит в первой четверти');
if (x<0) and (y>0) then writeln ('Точка лежит во второй четверти');
if (x<0) and (y<0) then writeln ('Точка лежит в третьей четверти');
if (x>0) and (y<0) then writeln ('Точка лежит в четвертой четверти');
if (x=0) and (y=0) then writeln ('Точка лежит на пересечении осей') else
if x=0 then writeln ('Точка лежит на оси ординат') else if y=0 then writeln ('Точка лежит на оси абсцисс');
readln;
end.