Computer Programming Contest Preparation

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



/home/toolbox/public_html/solutions/125/12527/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 #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: 2012-12-16
   21  * Purpose: fun
   22  * Problem: 12527 - Different Digits
   23  */
   24 
   25 /*
   26  * This template reads lines of data at a time until end of file.
   27  */
   28 
   29 int n;
   30 int m;
   31 int list[5001];
   32 int digits[10];
   33 
   34 int dupes(int x)
   35 {
   36     /* FUNCTON dupes */
   37     /* this returns 1 if duplicate digits found, otherwise it returns 0 */
   38     int i;
   39     int toReturn = 1;
   40     int tmp;
   41     int over999;
   42     int over99;
   43     int over9;
   44 
   45     tmp = x;
   46     over999 = (999 < x);
   47     over99 = (over999) || (99 < x);
   48     over9 = (over99) || (9 < x);
   49     for (i=0; 10>i; i++)
   50         {
   51             digits[i] = 0;
   52         }
   53     if (over999)
   54         {
   55             /* thousands digit present */
   56             digits[tmp / 1000] = 1;
   57             tmp = tmp % 1000;
   58         } /* thousands digit present */
   59     if ((over99) || (99 < tmp))
   60         {
   61             /* hundreds digit present */
   62             digits[tmp / 100] += 1;
   63             tmp = tmp % 100;
   64         } /* hundreds digit present */
   65     if ((over9) || (9 < tmp))
   66         {
   67             /* tens digit present */
   68             digits[tmp / 10] += 1;
   69             tmp = tmp % 10;
   70         } /* tens digit present */
   71     digits[tmp] += 1;
   72     for (i=0; 10>i; i++)
   73         {
   74             if (1 < digits[i])
   75                 {
   76                     toReturn = 0;
   77                 }
   78         }
   79     return toReturn;
   80 } /* FUNCTON dupes */
   81 
   82 void init()
   83 {
   84     /* FUNCTION init */
   85     int i;
   86 
   87     for(i=0; 11>i; i++)
   88         {
   89             list[i] = 1;
   90         }
   91     for (i=11; 5001>i; i++)
   92         {
   93             /* check the number */
   94             list[i] = dupes(i);
   95         } /* check the number */
   96 } /* FUNCTION init */
   97 
   98 void dump()
   99 {
  100     /* FUNCTION dump */
  101 } /* FUNCTION dump */
  102 
  103 int getInput()
  104 {
  105     /* FUNCTION getInput */
  106     int dataReadFlag;
  107 
  108     dataReadFlag = (2 == scanf(" %d %d ", &n, &m));
  109     return (dataReadFlag);
  110 } /* FUNCTION getInput */
  111 
  112 void process()
  113 {
  114     /* FUNCTION process */
  115     int tot = 0;
  116     int i;
  117 
  118     for (i=n; m>=i; i++)
  119         {
  120             /* add up number of valid houses */
  121             tot = tot + list[i];
  122         } /* add up number of valid houses */
  123     printf("%d\n", tot);
  124 } /* FUNCTION process */
  125 
  126 int main()
  127 {
  128     /* main */
  129     int moreToDo;
  130 
  131     init();
  132     moreToDo = getInput();
  133     while (moreToDo)
  134         {
  135             /* while */
  136             process();
  137             moreToDo = getInput();
  138         } /* while */
  139 
  140     return EXIT_SUCCESS;
  141 } /* main */
  142