Skip to content

Instantly share code, notes, and snippets.

@vieirin
Last active May 24, 2016 04:27
Show Gist options
  • Save vieirin/9cdf27d2e071daf6da798c3784fade59 to your computer and use it in GitHub Desktop.
Save vieirin/9cdf27d2e071daf6da798c3784fade59 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char const *argv[])
{
int right = 0, up = 0;
int input;
do
{
scanf("%d", &input);
switch(input){
case 0:
break;
case 1:
right++;
break;
case -1:
right--;
break;
case 2:
up++;
break;
case -2:
up--;
break;
default:
break;
}
} while (input != 0);
int command;
if (right != 0 || up != 0)
printf("Piloto automático ligado\n");
if (right > 0)
while(right > 0){
printf("-1\n");
right--;
command++;
}
else
while(right < 0){
printf("1\n");
right++;
command++;
}
if (up > 0)
while(up > 0){
printf("-2\n");
up--;
command++;
}
else
while(up < 0){
printf("2\n");
up++;
command++;
}
printf("Viagem terminada: veículo na base\n");
if(command > 0)
printf("Piloto automático ligado durante %d comandos\n", command);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment