import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int n = sc.nextInt(); List<Integer> list =new ArrayList<>(); for (int i = 0; i < n; i++) { list.add(sc.nextInt()); } System.out.println(Collections.max(list) - Collections.min(list)); } } }
#include<stdio.h> int main(void){ int n; int arr[10000]; int min, max; scanf("%d", &n); // 输入分数的个数 for(int i = 0; i < n; i++){ // 输入分数数列 scanf("%d", &arr[i]); } min = max = arr[0]; // 令min和max等于arr数组中的任意一个元素 for(int i = 0; i < n; i++){ // 求最大值和最小值 if(min > arr[i]) min = arr[i]; if(max < arr[i]) max = arr[i]; } printf("%d\n", max - min); // 输出最高分和最低分之差 return 0; }
#include <stdio.h> void sort(int a[],int n) { int i,j; for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[j]<a[i]) { int temp = a[j]; a[j] = a[i]; a[i] = temp; } } } } int main(){ int i,n,a[100]; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&a[i]); sort(a,n); printf("%d",a[n-1]-a[0]); return 0; }
import java.util.Arrays; import java.util.Scanner; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int num=sc.nextInt(); sc.nextLine(); String[] str=sc.nextLine().split(" "); int[] score=new int[str.length]; for (int i=0;i<str.length;i++){ score[i]=Integer.parseInt(str[i]); } Arrays.sort(score); int max=score[str.length-1]; int min=score[0]; int cha=max-min; System.out.println(cha); } }
#include<stdio.h> int main() { int n=0; scanf("%d",&n); int arr[n]; int i=0; for(i=0;i<n;i++) { scanf("%d",&arr[i]); } int max=arr[0]; for(i=1;i<n;i++) { if(arr[i]>max) max=arr[i]; } int min=arr[0]; for(i=1;i<n;i++) { if(arr[i]<min) min=arr[i]; } printf("%d\n",max-min); return 0; }
#include <stdio.h> int main() { int s,d,f,q ;//d,f分别为最小值和最大值 scanf("%d",&q); int a[q]; d=101;f=-1; for(s=0;s<q;s++) { scanf("%d",&a[s]); if(a[s]<d) { d=a[s]; } if(a[s]>f) { f=a[s]; } } printf("%d",f-d); return 0; }
#include<stdio.h> int main() { int n=0,m=0,max=0,min=100; scanf("%d",&n); while(n) { scanf("%d ",&m); if(m>max) max=m; if(m<min) min=m; n--; } printf("%d\n",max-min); return 0; }
#include<stdio.h> int main() { int n , i , j , k , max , min ; scanf("%d",&n); int str[n] , str0[n]; for(i = 0 ; i < n ; i++) { scanf("%d",&str[i]); str0[i] = str[i]; } for(k = 0 ; k < n - 1 ; k++) { if(str[k] > str[k+1]) str[k+1] = str[k]; } max = str[n-1]; for(j = 0 ; j < n - 1 ; j++) { if(str0[j] < str0[j+1]) str0[j+1] = str0[j]; } min = str0[n-1]; printf("%d",max - min); return 0; }
#include <stdio.h> int main(){ int n = 0, arr[100] = { 0 }; scanf("%d", &n); for(int i = 0; i < n; i++){ scanf("%d", &arr[i]); } for(int i = 0; i < n; i++){ for(int j = i + 1; j < n; j++){ if(arr[i] > arr[j]){ int temp = arr[j]; arr[j] = arr[i]; arr[i] = temp; } } } printf("%d", arr[n-1] - arr[0]); return 0; }
#include<stdio.h> int main() { int n; scanf("%d",&n); int a[n],min=100,max=0; for(int i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<min) min=a[i]; if(a[i]>max) max=a[i]; } printf("%d",max-min); }
#include <stdio.h> int main() { int n,max=0,min=100,ret; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&ret); max=max>ret?max:ret; min=min<ret?min:ret; } printf("%d",max-min); return 0; }
#include <stdio.h> int main() { int n; scanf("%d",&n); int array[n]; int i,j,temp; for(i=0;i<n;i++) { scanf("%d",&array[i]); } for(i=0;i<n-1;i++) { for(j=0;j<n-i-1;j++) { if(array[j]>array[j+1]) { temp=array[j+1]; array[j+1]=array[j]; array[j]=temp; } } } printf("%d",(array[n-1]-array[0])); return 0; }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] nums = new int[n]; int max = 0, min = 100; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); } for (int i = 0; i < n; i++) { if (max < nums[i]) { max = nums[i]; } if (min > nums[i]) { min = nums[i]; } } int ret = max - min; System.out.println(ret); } }