Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/103/10340/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 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 #define MAX_LINE 500000
   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 s[MAX_LINE];
   29 char t[MAX_LINE];
   30 
   31 void init()
   32 {
   33     /* FUNCTION init */
   34 } /* FUNCTION init */
   35 
   36 void dump()
   37 {
   38     /* FUNCTION dump */
   39 } /* FUNCTION dump */
   40 
   41 int getInput()
   42 {
   43     /* FUNCTION getInput */
   44     int dataReadFlag;
   45     int tmp;
   46 
   47     tmp = scanf("%s %s", s, t);
   48     dataReadFlag = EOF != tmp;
   49 
   50     return (dataReadFlag);
   51 } /* FUNCTION getInput */
   52 
   53 int findChar(char chr, int start)
   54 {
   55     /* FUNCTION findChar */
   56     int i;
   57     int ret = -1;
   58     int tmp;
   59 
   60     tmp = strlen(t);
   61     for (i=start; (i<tmp) && (chr != t[i]); i++) {};
   62     if (i<tmp)
   63         {
   64             ret = i;
   65         }
   66 
   67     return ret;
   68 } /* FUNCTION findChar */
   69 
   70 void process()
   71 {
   72     /* FUNCTION process */
   73     int first;
   74     int second;
   75     int found = FALSE;
   76     int space;
   77     int sln;
   78 
   79     sln = strlen(s);
   80     space = findSpace();
   81     second = space + 1;
   82 
   83     DEBUG printf("[%s] space = %d    length = %d\n", line, space, sln);
   84     while ((! found) && (second < sln))
   85         {
   86             /* while still hunting */
   87             if (line[first] == line[second])
   88                 {
   89                     /* match found */
   90                     first ++;
   91                     found = (first == space);
   92                 } /* match found */
   93             second++;
   94         } /* while still hunting */
   95     if (found)
   96         printf("Yes\n");
   97     else
   98         printf("No\n");
   99 
  100 } /* FUNCTION process */
  101 
  102 int main()
  103 {
  104     /* main */
  105     int moreToDo;
  106 
  107     init();
  108     moreToDo = getInput();
  109     while (moreToDo)
  110         {
  111             /* while */
  112             process();
  113             moreToDo = getInput();
  114         } /* while */
  115 
  116     return EXIT_SUCCESS;
  117 } /* main */
  118