Computer Programming Contest Preparation

ToolBox - Source for: 115/11577/a.c



/home/toolbox/public_html/solutions/115/11577/a.c
    1 #include <stdio.h>
    2 #include <string.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
    6 #include <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2020-09-28
   20  * Purpose: fun
   21  * Problem: 11577
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_LINE 225
   29 
   30 int numberOfTimes;
   31 char line[MAX_LINE+1];
   32 int cnt[26];
   33 
   34 void init()
   35 {
   36     /* FUNCTION init */
   37     scanf("%d ", &numberOfTimes);
   38 } /* FUNCTION init */
   39 
   40 void dump()
   41 {
   42     /* FUNCTION dump */
   43 } /* FUNCTION dump */
   44 
   45 void getInput()
   46 {
   47     /* FUNCTION getInput */
   48     fgets(line, MAX_LINE, stdin);
   49 } /* FUNCTION getInput */
   50 
   51 void process()
   52 {
   53     /* FUNCTION process */
   54     int sl;
   55     int i;
   56     int mx = 0;
   57     int tmp;
   58 
   59     for (i=0; i<26; i++)
   60         {
   61             cnt[i] = 0;
   62         }
   63     sl = strlen(line);
   64     for (i=0; i<sl; i++)
   65         {
   66             /* for each char */
   67             if (isalpha(line[i]))
   68                 {
   69                     /* letter */
   70                     line[i] = tolower(line[i]);
   71                     tmp = line[i] - 'a';
   72                     cnt[tmp] = cnt[tmp] + 1;
   73                     mx = (mx < cnt[tmp]) ? cnt[tmp] : mx;
   74                 } /* letter */
   75         } /* for each char */
   76     /* now dump all max matches */
   77     for (i=0; i<26; i++)
   78         {
   79             /* for each letter */
   80             if (mx == cnt[i])
   81                 {
   82                     printf("%c", i+'a');
   83                 };
   84         } /* for each letter */
   85     printf("\n");
   86 } /* FUNCTION process */
   87 
   88 int main()
   89 {
   90     /* main */
   91     int i;
   92 
   93     init();
   94     for (i=0; i<numberOfTimes; i++)
   95         {
   96             /* while */
   97             getInput();
   98             process();
   99         } /* while */
  100 
  101     return EXIT_SUCCESS;
  102 } /* main */
  103 
  104