wojiaocbj

cbj

Mar 13th, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #pragma warning(disable:4996)
  7. typedef long long LL;
  8. typedef unsigned long long ULL;
  9. void minmax(int *a, int len, int *max, int *min){
  10.     int i;
  11.     *max = *min = a[0];
  12.     for(i = 0;i < len;i++){
  13.         if(a[i] > *max){
  14.             *max = a[i];
  15.         }
  16.         if(a[i] < *min){
  17.             *min = a[i];
  18.         }
  19.     }
  20. }
  21. int main(){
  22. #ifdef _DEBUG
  23.     FILE *fp = freopen("input.txt", "r", stdin);
  24.     //FILE *fp2 = freopen("output.txt", "w", stdout);
  25. #endif // _DEBUG
  26.     int t, n, m, M, a[1024] = { 0 }, i;
  27.     scanf("%d", &t);
  28.     while(t--){
  29.         scanf("%d", &n);
  30.         for(i = 0;i < n;i++){
  31.             scanf("%d", a + i);
  32.         }
  33.         minmax(a, n, &M, &m);
  34.         printf("%d\n", M - m);
  35.     }
  36.    
  37. #ifdef _DEBUG
  38.     freopen("CON", "r", stdin);
  39.     //freopen("CON", "w", stdout);
  40.     system("pause");
  41. #endif // _DEBUG
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment