nn.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #define ABS(x,y) (((x) > (y))? x - y : y - x)
00003 
00004 main(ac, av)
00005 int ac;
00006 char **av;
00007 {
00008   int tmp, min = 1000000, lineno = 0, minline = 0, minmax = 1000000;
00009   char s[BUFSIZ];
00010 
00011   if(ac < 3) {
00012     printf("0\n");
00013     exit();
00014   }
00015   if(ac == 3) minmax = atoi(av[2]);
00016   while(gets(s) != NULL) {
00017     lineno++;
00018     tmp = hamming(s, av[1]);
00019     if(min > tmp) {
00020       min = tmp;
00021       minline = lineno;
00022     }
00023   }
00024   if(minmax > min) 
00025     printf("%d\n", minline);
00026   else
00027     printf("0\n");
00028 }
00029     
00030 
00031 hamming(s1, s2)
00032 char *s1, *s2;
00033 {
00034   int i, j;
00035   for(i = j = 0; i < 26; i++) {
00036     j += ABS(s1[i], s2[i]);
00037   }
00038   return j;
00039 }
00040     
00041     


euslisp
Author(s): Toshihiro Matsui
autogenerated on Thu Sep 3 2015 10:36:20