Hiking Trail
Consider the following header file:
myheader.h
#ifndef _MYHEADER_H
#define _MYHEADER_H 1
int foo(char *, int);
#endif /* myheader.h */
download as text file
Write the function foo()
declared in myheader.h
that takes a string and a nonnegative integer n as parameters.
The string describes the current state of a hiking trail.
In the string, '!'
(exclamation mark) characters indicate the start, the finish, and the checkpoints of the trail,
the lowercase letters of the English alphabet indicate the hikers performing the trail, and '.'
(period) characters
denote other parts of the route.
The function should return the number of sections where more than n hikers are staying.
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 "myheader.h"
int main()
{
char line[1000];
int n;
while (scanf("%s %d", line, &n) != EOF)
printf("%d\n", foo(line, n));
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
!.........! 1
!...ab..c.!..d..e.!...! 1
!...abcde..!....!.....!......!.......! 5
download as text file
Output for Sample Input
0
2
0
download as text file
One possible solution is available in: main.c.
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.