Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int* moveInMaze(char* str, int* is_ok);
- int main() {
- char request_string[200];
- int* result;
- int is_ok = 1;
- fgets(request_string,200,stdin);
- result = moveInMaze(request_string, &is_ok);
- if(!is_ok){
- puts("invalid input command.\n");
- return 1;
- }
- printf("%d %d", result[0], result[1]);
- return 0;
- }
- int* moveInMaze(char* command, int* is_ok){
- #define ONE_NEW_LINE 1
- int length = strlen(command) - ONE_NEW_LINE;
- int static location[2] = {0,0};
- for(int i=0; i<length; i++) {
- switch (command[i])
- {
- case 'L': {
- location[0]--;
- break;
- }
- case 'R': {
- location[0]++;
- break;
- }
- case 'D': {
- location[1]--;
- break;
- }
- case 'U': {
- location[1]++;
- break;
- }
- default: {
- if(is_ok) *is_ok = 0;
- }
- }
- }
- return location;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement