Advertisement
cd62131

Diff

Feb 18th, 2014
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <limits.h>
  4. int main(int argc, char **argv) {
  5.   FILE *sample = fopen(argv[1], "r");
  6.   FILE *input = fopen(argv[2], "r");
  7.   int x, y, min = INT_MAX, s[6], in[4], cand;
  8.   fscanf(input, "%d,%d,%d,%d", &in[0], &in[1], &in[2], &in[3]);
  9.   while (fscanf(sample, "%d,%d,%d,%d,%d,%d",
  10.     &s[0], &s[1], &s[2], &s[3], &s[4], &s[5]) != EOF) {
  11.     cand = (s[2] - in[0]) * (s[2] - in[0]) +
  12.       (s[3] - in[1]) * (s[3] - in[1]) +
  13.       (s[4] - in[2]) * (s[4] - in[2]) +
  14.       (s[5] - in[3]) * (s[5] - in[3]);
  15.     if (min > cand) {
  16.       min = cand;
  17.       x = s[0];
  18.       y = s[1];
  19.     }
  20.   }
  21.   fclose(sample);
  22.   fclose(input);
  23.   printf("%d,%d\n", x, y);
  24.   return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement