Last active
May 24, 2016 04:27
-
-
Save vieirin/9cdf27d2e071daf6da798c3784fade59 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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