Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 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 (1)
  18. {
  19. ch = fgetc( fp);
  20. if (ch == ' ' || ch == '\n' || ch == '\r' || ch == EOF) {
  21. if (fl == 1) {
  22. n[f ] = '\0';
  23. k[count] = atoi(n);
  24. if (k[count] > max && count > 0)
  25. {
  26. max = k[count];
  27. }
  28. if (k[count] < min && count > 0)
  29. {
  30. min = k[count];
  31. }
  32. if (ch == EOF)
  33. {
  34. break;
  35. }
  36. f = 0;
  37. n[0] = '\0';
  38. count++;
  39. fl = 0;
  40. }
  41. if (ch == '\n')
  42. {
  43. countn++;
  44. if (countn == 2)
  45. {
  46. break;
  47. }
  48. }
  49. continue;
  50. }
  51. else {
  52. n[f] = ch;
  53. if (f == 99) break;
  54. f++;
  55. fl = 1;
  56. }
  57. }
  58. if (count + 1 != k[0] || count == 0)
  59. {
  60. exit(1);
  61. }
  62. for (int i = 1; i <= k[0] ; ++i)
  63. {
  64. if (k[i] == max)
  65. {
  66. k[i] = min;
  67. }
  68. printf("%i ", k[i]);
  69. }
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement