Computer Programming Contest Preparation

ToolBox - Source for: 125/12554/a.c



/home/toolbox/public_html/solutions/125/12554/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 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /* fprintf(stderr, "functionName: message", varslist); */
   17 
   18 /*
   19  *  Author: Isaac Traxler
   20  *    Date: 2021-11-17
   21  * Purpose: fun
   22  * Problem: 12554 - A Special “Happy Birthday” Song!!!
   23  */
   24 
   25 /*
   26  * This template reads data a specified number of times.
   27  */
   28 
   29 #define MAX_NAMES 101
   30 #define MAX_NAME_LENGTH 102
   31 
   32 int numberOfTimes;
   33 char song[16][9];
   34 char names[MAX_NAMES][MAX_NAME_LENGTH];
   35 
   36 void init()
   37 {
   38     /* FUNCTION init */
   39 
   40     scanf("%d ", &numberOfTimes);
   41     strcpy(song[0], "Happy");
   42     strcpy(song[1], "birthday");
   43     strcpy(song[2], "to");
   44     strcpy(song[3], "you");
   45     strcpy(song[4], "Happy");
   46     strcpy(song[5], "birthday");
   47     strcpy(song[6], "to");
   48     strcpy(song[7], "you");
   49     strcpy(song[8], "Happy");
   50     strcpy(song[9], "birthday");
   51     strcpy(song[10], "to");
   52     strcpy(song[11], "Rujia");
   53     strcpy(song[12], "Happy");
   54     strcpy(song[13], "birthday");
   55     strcpy(song[14], "to");
   56     strcpy(song[15], "you");
   57 } /* FUNCTION init */
   58 
   59 void dump()
   60 {
   61     /* FUNCTION dump */
   62 } /* FUNCTION dump */
   63 
   64 void getInput()
   65 {
   66     /* FUNCTION getInput */
   67     int i;
   68 
   69     for (i=0; numberOfTimes>i; i++)
   70         {
   71             /* read each name */
   72             scanf(" %s ", names[i]);
   73         } /* read each name */
   74 } /* FUNCTION getInput */
   75 
   76 void process()
   77 {
   78     /* FUNCTION process */
   79     int i = 0;
   80     int cnt = 0;
   81     int songFinished = FALSE;
   82     int peopleFinished = FALSE;
   83 
   84     while (! songFinished)
   85         {
   86             /* while */
   87             printf("%s: %s\n", names[i], song[cnt]);
   88             i++;
   89             if (numberOfTimes == i)
   90                 {
   91                     /* finished last person */
   92                     i = 0;
   93                     peopleFinished = TRUE;
   94                 } /* finished last person */
   95             cnt++;
   96             if (16 == cnt)
   97                 {
   98                     /* restart song over */
   99                     cnt = 0;
  100                     songFinished = peopleFinished;
  101                 } /* restart song over */
  102         } /* while */
  103 } /* FUNCTION process */
  104 
  105 int main()
  106 {
  107     /* main */
  108     int i;
  109 
  110     init();
  111     getInput();
  112     process();
  113 
  114     return EXIT_SUCCESS;
  115 } /* main */
  116 
  117