Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define INPUT_ERR -1
- #define RIGHT 0
- #define NOT_ENOUGH -2
- #define INF -1569325956
- int process(FILE *f, int *max1, int *max2)
- {
- int bal;
- if(!fscanf(f, "%d", max1))
- return INPUT_ERR;
- if(!fscanf(f, "%d", max2))
- return INPUT_ERR;
- while (1)
- {
- if (*max1 < *max2)
- {
- int tmp = *max1;
- *max1 = *max2;
- *max2 = tmp;
- }
- if(!fscanf(f, "%d", &bal))
- return INPUT_ERR;
- if (bal > *max2)
- {
- *max2 = bal;
- if (*max2 > *max1)
- {
- int tmp = *max1;
- *max1 = *max2;
- *max2 = tmp;
- }
- }
- }
- return RIGHT;
- }
- int main()
- {
- int max1 = INF, max2 = INF;
- FILE *file = stdin;
- process(file, &max1, &max2);
- if (max1 == INF || max2 == INF)
- {
- printf ("Недостаточно данных!\n");
- return NOT_ENOUGH;
- }
- if (!process(file, &max1, &max2))
- {
- printf("Ошибка!!!");
- return INPUT_ERR;
- }
- printf("max1 = %d; max2 = %d\n", max2, max1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement