fork download
  1. #include <assert.h>
  2. #include <limits.h>
  3. #include <math.h>
  4. #include <stdbool.h>
  5. #include <stddef.h>
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10.  
  11. char* readline();
  12. char** split_string(char*);
  13.  
  14. // Complete the miniMaxSum function below.
  15. void miniMaxSum(int arr_count, int* arr) {
  16. static long long int result[5];
  17. long long int sum=0;
  18.  
  19. for(int i=0;i<arr_count;i++)
  20. {
  21. sum=sum+arr[i];
  22.  
  23. }
  24. for(int j=0;j<arr_count;j++)
  25. {result[j]=sum-arr[j];}
  26.  
  27. long long int max=result[0],min=result[0];
  28.  
  29. for(int x=0;x<arr_count;x++)
  30. { if(max<result[x])
  31. {max=result[x];}
  32. else if (min>result[x])
  33. {min=result[x];}
  34.  
  35.  
  36.  
  37. }
  38. printf("%d"" ""%d",min,max);
  39.  
  40.  
  41. }
  42.  
  43. int main()
  44. {
  45. char** arr_temp = split_string(readline());
  46.  
  47. int* arr = malloc(5 * sizeof(int));
  48.  
  49. for (int i = 0; i < 5; i++) {
  50. char* arr_item_endptr;
  51. char* arr_item_str = *(arr_temp + i);
  52. int arr_item = strtol(arr_item_str, &arr_item_endptr, 10);
  53.  
  54. if (arr_item_endptr == arr_item_str || *arr_item_endptr != '\0') { exit(EXIT_FAILURE); }
  55.  
  56. *(arr + i) = arr_item;
  57. }
  58.  
  59. int arr_count = 5;
  60.  
  61. miniMaxSum(arr_count, arr);
  62.  
  63. return 0;
  64. }
  65.  
  66. char* readline() {
  67. size_t alloc_length = 1024;
  68. size_t data_length = 0;
  69. char* data = malloc(alloc_length);
  70.  
  71. while (true) {
  72. char* cursor = data + data_length;
  73. char* line = fgets(cursor, alloc_length - data_length, stdin);
  74.  
  75. if (!line) { break; }
  76.  
  77. data_length += strlen(cursor);
  78.  
  79. if (data_length < alloc_length - 1 || data[data_length - 1] == '\n') { break; }
  80.  
  81. size_t new_length = alloc_length << 1;
  82. data = realloc(data, new_length);
  83.  
  84. if (!data) { break; }
  85.  
  86. alloc_length = new_length;
  87. }
  88.  
  89. if (data[data_length - 1] == '\n') {
  90. data[data_length - 1] = '\0';
  91. }
  92.  
  93. data = realloc(data, data_length);
  94.  
  95. return data;
  96. }
  97.  
  98. char** split_string(char* str) {
  99. char** splits = NULL;
  100. char* token = strtok(str, " ");
  101.  
  102. int spaces = 0;
  103.  
  104. while (token) {
  105. splits = realloc(splits, sizeof(char*) * ++spaces);
  106. if (!splits) {
  107. return splits;
  108. }
  109.  
  110. splits[spaces - 1] = token;
  111.  
  112. token = strtok(NULL, " ");
  113. }
  114.  
  115. return splits;
  116. }
  117.  
Success #stdin #stdout 0s 5380KB
stdin
1 2 3 4 5
stdout
10 14