Computer Programming Contest Preparation

ToolBox - Source for: naq/naq2022/c.c



/home/toolbox/public_html/solutions/naq/naq2022/c.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 <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 #define MAX_LINE 257
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date:
   21  * Purpose: fun
   22  * Problem: NAQ - c
   23  */
   24 
   25 /*
   26  * This template reads lines of data at a time until end of file.
   27  */
   28 
   29 char line[MAX_LINE];
   30 int count[26];
   31 
   32 void init()
   33 {
   34     /* FUNCTION init */
   35     int i;
   36 
   37     for (i=0; 26>i; i++)
   38         {
   39             count[i] = 0;
   40         }
   41 } /* FUNCTION init */
   42 
   43 void dump()
   44 {
   45     /* FUNCTION dump */
   46 } /* FUNCTION dump */
   47 
   48 void getInput()
   49 {
   50     /* FUNCTION getInput */
   51     int i;
   52     int slen;
   53 
   54     fgets(line, MAX_LINE, stdin);
   55     slen = strlen(line) - 1;
   56     for (i=0; slen > i; i++)
   57         {
   58             /* for */
   59             count[line[i]-'a'] =  count[line[i]-'a'] + 1;
   60         } /* for */
   61 } /* FUNCTION getInput */
   62 
   63 void process()
   64 {
   65     /* FUNCTION process */
   66     int i;
   67     int j;
   68 
   69     for (i=0; 26>i; i++)
   70         {
   71             /* for each letter */
   72             for (j=0; count[i] > j; j++)
   73                 {
   74                     /* for each occurrence of the letter */
   75                     printf("%c", i+'a');
   76                 } /* for each occurrence of the letter */
   77         } /* for each letter */
   78     printf("\n");
   79 } /* FUNCTION process */
   80 
   81 int main()
   82 {
   83     /* main */
   84 
   85     init();
   86     getInput();
   87     getInput();
   88     process();
   89 
   90     return EXIT_SUCCESS;
   91 } /* main */
   92