Programming contests

50 Programming Exercise for Beginners

January 2, 2019, 12:00 AM – December 31, 2019, 12:00 AM

At the Beginning of the Alphabet

Consider the following header file:

myheader.h

  1. #ifndef _MYHEADER_H
  2. #define _MYHEADER_H 1
  3. char foo(const char *);
  4. #endif /* myheader.h */
download as text file

Write the function foo() declared in myheader.h that takes a string as a parameter containing only uppercase letters of the English alphabet. The function should determine and return the letter of the string that is the first in alphabetical order. Make sure that the original string does not change.

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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "myheader.h"
  4. int main()
  5. {
  6.     char line[100];
  7.     while (gets(line) != NULL)
  8.         printf("%c\n", foo(line));
  9.     return EXIT_SUCCESS;
  10. }
download as text file

Makefile

  1. SRCS = main.c foo.c
  2. OBJS = $(SRCS:%.c=%.o)
  3. TARGETS = main
  4. .PHONY: clean
  5. all: $(TARGETS)
  6. main: $(OBJS)
  7. $(CC) $(OBJS) -o main
  8. %.o: %.c
  9. $(CC) -Wall -c $< -o $@
  10. clean:
  11. rm -rf $(OBJS) *~ $(TARGETS)
download as text file

Sample Input

  1. ALMA
  2. MEGGY
  3. MOTOR
download as text file

Output for Sample Input

  1. A
  2. E
  3. M
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.
University of Debrecen; Faculty of Informatics; v. 09/30/2024