Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. int main() {
  5. FILE* fp;
  6. fp = fopen("input.txt", "r");
  7. int max = 0;
  8. int count = 0;
  9. int k[100];
  10. char n[100];
  11. n[0] = '\0';
  12. int min = 1000000;
  13. char ch;
  14. int f = 0;
  15. int countn = 0;
  16. int fl = 0;
  17. while ((ch = fgetc( fp)) != EOF)
  18. {
  19. if (ch == ' ' || ch == '\n' || ch == '\r') {
  20. if (fl == 1) {
  21. n[f ] = '\0';
  22. k[count] = atoi(n);
  23. if (k[count] > max)
  24. {
  25. max = k[count];
  26. }
  27. if (k[count] < min)
  28. {
  29. min = k[count];
  30. }
  31. f = 0;
  32. n[0] = '\0';
  33. count++;
  34. }
  35. if (ch == '\n')
  36. {
  37. countn++;
  38. if (countn == 2)
  39. {
  40. break;
  41. }
  42. }
  43. continue;
  44. }
  45. else {
  46. n[f] = ch;
  47. if (f == 99) break;
  48. f++;
  49. fl = 1;
  50. }
  51. }
  52. for (int i = 1; i < k[0] ; ++i)
  53. {
  54. if (k[i] == max)
  55. {
  56. k[i] = min;
  57. }
  58. printf("%i ", k[i]);
  59. }
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement