1 条题解

  • 0
    @ 2021-6-15 12:56:59

    C++ :

    #include<iostream>
    
    using namespace std;
    
    int a[1000005];
    int main()
    {
    	int max,min,n,p1,p2;
    	cin>>n;
    	max=-1000000;
    	min=1000000;
    	for (int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    	}
    	for (int i=1;i<=n;i++)
    	{
    		if (a[i]>max){max=a[i]; p1=i;}
    		if (a[i]<min) {min=a[i]; p2=i;}
    	}
    	cout<<"max"<<"="<<max<<" "<<"("<<p1<<")"<<endl;
    	cout<<"min"<<"="<<min<<" "<<"("<<p2<<")"<<endl;
    	return 0;
    }
    

    Pascal :

    var n,i,max,min,maxp,minp:longint;
        a:array[1..100] of longint;
    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 a[i]>max then begin max:=a[i]; maxp:=i; end;
           if a[i]<min then begin min:=a[i]; minp:=i; end;
         end;
      writeln('max=',max,' (',maxp,')');
      writeln('min=',min,' (',minp,')');
    end.
    
    • 1

    信息

    ID
    752
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者