Advertisement
Alx09

Ex3

Apr 23rd, 2020
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. unsigned Abs(unsigned a, unsigned b) {
  5. if (a > b)
  6. return a - b;
  7. return b - a;
  8. }
  9.  
  10. int main() {
  11. unsigned i, j, k, n, dist, distMaxim = 0;
  12. FILE *f;
  13. f = fopen("srv.in", "r");
  14. if (!f) return 0;
  15. fscanf(f, "%u", &n);
  16. for (k = 1; k <= n; k++) {
  17. fscanf(f, "%u%u", &i, &j);
  18. if (Abs(i, j) <= n)
  19. dist = Abs(i, j);
  20. else
  21. dist = 2 * n - Abs(i, j);
  22. if (dist > distMaxim)
  23. distMaxim = dist;
  24. }
  25. fclose(f);
  26. f = fopen("srv.out", "w");
  27. fprintf(f, "%u", distMaxim);
  28. fclose(f);
  29. return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement