Created
February 26, 2014 17:01
-
-
Save Danilo/9233675 to your computer and use it in GitHub Desktop.
jumping mario
This file contains 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> | |
#include <string.h> | |
int main(int argc, char *argv[]) | |
{ | |
FILE *fp; | |
int tries = 0; | |
int jump = 0; | |
int low_jump = 0; | |
int high_jump = 0; | |
int number_of_walls = 0; | |
int times_to_execute = 0; | |
char jump_sequence[1024]; | |
char output_buffer[1024]; | |
memset(jump_sequence, 0, sizeof(jump_sequence)); | |
memset(output_buffer, 0, sizeof(output_buffer)); | |
fp = fopen(argv[argc-2], "r"); | |
fscanf(fp, "%d\n", ×_to_execute); | |
for (tries = 1; times_to_execute >= tries; tries++) | |
{ | |
jump = 0; | |
low_jump = 0; | |
high_jump = 0; | |
fscanf(fp, "%d\n", &number_of_walls); | |
fgets(jump_sequence, sizeof(jump_sequence), fp); | |
while (42) | |
{ | |
if (jump > ((number_of_walls-2)*2)) break; | |
if ((jump % 2) == 0) | |
{ | |
if (atoi(&jump_sequence[jump]) > atoi(&jump_sequence[jump+2])) low_jump++; | |
else if (atoi(&jump_sequence[jump]) < atoi(&jump_sequence[jump+2])) high_jump++; | |
} | |
jump++; | |
} | |
sprintf(&output_buffer[strlen(output_buffer)], "Case %d: %d %d\n", tries, high_jump, low_jump); | |
} | |
fclose(fp); | |
fp = fopen(argv[argc-1], "w"); | |
fwrite(output_buffer, 1, strlen(output_buffer), fp); | |
fclose(fp); | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment