Computer Programming Contest Preparation

ToolBox - Source for: 103/10340/a.c



/home/toolbox/public_html/solutions/103/10340/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 <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 #define MAX_LINE 1000000
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date:
   20  * Purpose: fun
   21  * Problem:
   22  */
   23 
   24 /*
   25  * This template reads lines of data at a time until end of file.
   26  */
   27 
   28 char line[MAX_LINE];
   29 
   30 void init()
   31 {
   32     /* FUNCTION init */
   33 } /* FUNCTION init */
   34 
   35 void dump()
   36 {
   37     /* FUNCTION dump */
   38 } /* FUNCTION dump */
   39 
   40 int getInput()
   41 {
   42     /* FUNCTION getInput */
   43     int dataReadFlag;
   44 
   45     fgets(line, MAX_LINE, stdin);
   46     if (feof(stdin))
   47         dataReadFlag = FALSE;
   48     else
   49         {
   50             /* something to read */
   51             dataReadFlag = TRUE;
   52             line[strlen(line)-1] = 0;
   53         } /* something to read */
   54     return (dataReadFlag);
   55 } /* FUNCTION getInput */
   56 
   57 int findSpace()
   58 {
   59     /* FUNCTION findSpace */
   60     int i;
   61     int tmp;
   62 
   63     tmp = strlen(line);
   64     for (i=0; (! isspace(line[i])); i++) {};
   65 
   66     return i;
   67 } /* FUNCTION findSpace */
   68 
   69 int findChar(char chr, int start)
   70 {
   71     /* FUNCTION findChar */
   72     int i;
   73     int ret = -1;
   74     int tmp;
   75 
   76     tmp = strlen(line);
   77     for (i=start; (i<tmp) && (chr != line[i]); i++) {};
   78     if (i<tmp)
   79         {
   80             ret = i;
   81         }
   82 
   83     return ret;
   84 } /* FUNCTION findChar */
   85 
   86 void process()
   87 {
   88     /* FUNCTION process */
   89     int first;
   90     int second;
   91     int found = FALSE;
   92     int space;
   93     int sln;
   94 
   95     sln = strlen(line);
   96     space = findSpace();
   97     second = space + 1;
   98     first = 0;
   99 
  100     while ((! found) && (second < sln))
  101         {
  102             /* while still hunting */
  103             if (line[first] == line[second])
  104                 {
  105                     /* match found */
  106                     first ++;
  107                     found = (first == space);
  108                 } /* match found */
  109             second++;
  110         } /* while still hunting */
  111     if (found)
  112         printf("Yes\n");
  113     else
  114         printf("No\n");
  115 
  116 } /* FUNCTION process */
  117 
  118 int main()
  119 {
  120     /* main */
  121     int moreToDo;
  122 
  123     init();
  124     moreToDo = getInput();
  125     while (moreToDo)
  126         {
  127             /* while */
  128             process();
  129             moreToDo = getInput();
  130         } /* while */
  131 
  132     return EXIT_SUCCESS;
  133 } /* main */
  134