Robot faqat to’rtta tomonga ko’cha oladi(‘s’-shimol, ‘j’-janub, ‘q’-sharq, ‘g’-g’arb) va uchta raqamli kamanda: 0-harakatni davom ettir, 1-chapga buril, 2-o’nga buril. Y-robot yo’nalishi va k-kamanda berilgan


Download 47.72 Kb.
Sana04.01.2023
Hajmi47.72 Kb.
#1079049
Bog'liq
dasturlash1


1.1
;

1.2
Robot faqat to’rtta tomonga ko’cha oladi(‘s’-shimol, ‘j’-janub, ‘q’-sharq, ‘g’-g’arb) va uchta raqamli kamanda: 0-harakatni davom ettir, 1-chapga buril, 2-o’nga buril. Y-robot yo’nalishi va K-kamanda berilgan. Berilgan kamanda bajarildan keying robot holatini aniqlovchi dastur tuzilsin.


#include
using namespace std;
int main(){
char c;
int cur;
cout<<"robot turgan joyni kiriting(s-shimol, j-janub, q-sharq, g-garb)";cin>>c;
switch (c)
{
case 's':cur=1;break;
case 'j':cur=3;break;
case 'q':cur=4;break;
case 'g':cur=2;break;
default:cur=1;break;
}
int com;
do{
cout<<"0-stop, 1-chapga buril, 2-o'nga buril";cin>>com;
if(com==1) cur--;
else cur++;
if(cur==0) cur=4;
else if(cur==5) cur=1;
}while(com!=0);
switch(cur){
case 1:cout<<"shimol";break;
case 2:cout<<"g'arb";break;
case 3:cout<<"janub";break;
case 4:cout<<"sharq";break;
}
}

Download 47.72 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling