Advertisement
thelost

Untitled

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