1 solutions

  • 0
    @ 2025-11-5 15:09:26

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int n,a[90999];
    int main()
    {
     	cin>>n;
     	for(int i=1;i<=n;i++)
     		cin>>a[i];
     	sort(a+1,a+1+n);
    	cout<<a[n]-a[1];	
     	return 0;
    }
    

    Pascal :

    var a:array[1..1000]of integer;
        max,min,i,n:integer;
    begin
      readln(n);
      for i:=1 to n do read(a[i]);
      max:=a[1]; min:=a[1];
      for i:=1 to n do
        begin
          if max<a[i] then max:=a[i];  
          if min>a[i] then min:=a[i]; 
        end;
      write(max-min);
    end. 
    

    Python :

    # coding=utf-8
    N=int(input())
    string=input()
    L=string.split(" ")
    mylist=[]  #创建空列表
    for s in L:
        mylist.append(int(s))
    print(max(mylist)-min(mylist))
    
    
    • 1

    Information

    ID
    16454
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By