Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <limits.h>
- int main(int argc, char **argv) {
- FILE *sample = fopen(argv[1], "r");
- FILE *input = fopen(argv[2], "r");
- int x, y, min = INT_MAX, s[6], in[4], cand;
- fscanf(input, "%d,%d,%d,%d", &in[0], &in[1], &in[2], &in[3]);
- while (fscanf(sample, "%d,%d,%d,%d,%d,%d",
- &s[0], &s[1], &s[2], &s[3], &s[4], &s[5]) != EOF) {
- cand = (s[2] - in[0]) * (s[2] - in[0]) +
- (s[3] - in[1]) * (s[3] - in[1]) +
- (s[4] - in[2]) * (s[4] - in[2]) +
- (s[5] - in[3]) * (s[5] - in[3]);
- if (min > cand) {
- min = cand;
- x = s[0];
- y = s[1];
- }
- }
- fclose(sample);
- fclose(input);
- printf("%d,%d\n", x, y);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement