Drone Images
Many hikers are walking in the hiking trails of Hungary even in rainy weather.
In this case, we can spot two things in an image of the pathway created by a drone: people and puddles.
Given the current situation of the hikers and knowing that all hikers want to keep clear of the puddles,
it is easy to determine the position of the hikers in the moment after the next step.
Hikers go from left to right on the pathways, and in the moment after the next step, they all move to
the next place where there is no puddle. Thus, there will be hikers who take only a small step to the next
adjacent section of the pathway, but there will be some who have to jump to the section of the pathway that
follows the puddles in front of them.
Consider the following header file:
myheader.h
#ifndef _MYHEADER_H
#define _MYHEADER_H 1
void foo(const char *, char *);
#endif /* myheader.h */
download as text file
Write the function foo()
declared in myheader.h that takes the address of two strings as parameters.
The first string describes a pathway, in which an asterisk character ('*
') denotes a hiker, an
at sign ('@
') denotes a puddle, and an equal sign ('=
') indicates a free passage of the pathway.
The foo()
function should compute the position of the hikers in the next moment and store it in a string of the same format as the input. You may assume that no one in the starting position has reached the goal of the tour, nor has the target flag been set in a puddle, so there will be at least one free passage in front of each participant.
Note
Place the function in file foo.c
and submit this file as a solution to the evaluation system. You can test your solution using the following files. The evaluation system does not necessarily perform the evaluation using these files.
main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "myheader.h"
int main()
{
char source[100], destination[100];
while (fgets(source, 100, stdin) != NULL)
{
if (source[strlen(source) - 1] == '\n')
source[strlen(source) - 1] = '\0';
foo(source, destination);
printf("%s\n", destination);
}
return EXIT_SUCCESS;
}
download as text file
Makefile
SRCS = main.c foo.c
OBJS = $(SRCS:%.c=%.o)
TARGETS = main
.PHONY: clean
all: $(TARGETS)
main: $(OBJS)
$(CC) $(OBJS) -o main
%.o: %.c
$(CC) -Wall -c $< -o $@
clean:
rm -rf $(OBJS) *~ $(TARGETS)
download as text file
Sample Input
==*====*====
===@===
**@@@==*@@=*@*=
*=*=*=*=*=*=
==*@===*=*@=
download as text file
Output for Sample Input
===*====*===
===@===
=*@@@*==@@*=@**
=*=*=*=*=*=*
===@*===*=@*
download as text file
Acknowledgement
This work was supported by the construction EFOP-3.4.3-16-2016-00021. The project was supported by the European Union, co-financed by the European Social Fund.