Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define INPUT_ERR -1
  6. #define RIGHT 0
  7. #define NOT_ENOUGH -2
  8. #define INF -1569325956
  9.  
  10. int process(FILE *f, int *max1, int *max2)
  11. {
  12. int bal;
  13. if(!fscanf(f, "%d", max1))
  14. return INPUT_ERR;
  15. if(!fscanf(f, "%d", max2))
  16. return INPUT_ERR;
  17. while (1)
  18. {
  19. if (*max1 < *max2)
  20. {
  21. int tmp = *max1;
  22. *max1 = *max2;
  23. *max2 = tmp;
  24. }
  25. if(!fscanf(f, "%d", &bal))
  26. return INPUT_ERR;
  27. if (bal > *max2)
  28. {
  29. *max2 = bal;
  30. if (*max2 > *max1)
  31. {
  32. int tmp = *max1;
  33. *max1 = *max2;
  34. *max2 = tmp;
  35. }
  36. }
  37. }
  38. return RIGHT;
  39. }
  40.  
  41. int main()
  42. {
  43. int max1 = INF, max2 = INF;
  44.  
  45. FILE *file = stdin;
  46.  
  47. process(file, &max1, &max2);
  48.  
  49. if (max1 == INF || max2 == INF)
  50. {
  51. printf ("Недостаточно данных!\n");
  52. return NOT_ENOUGH;
  53. }
  54. if (!process(file, &max1, &max2))
  55. {
  56. printf("Ошибка!!!");
  57. return INPUT_ERR;
  58. }
  59. printf("max1 = %d; max2 = %d\n", max2, max1);
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement