1 条题解

  • 0
    @ 2021-6-15 10:13:25

    C :

    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    int main()
    {
    	int a[100000];
    	int i, j, n;
    	int min = 0, max = 0, maxp = 0, minp = 0;
    	scanf("%d", &n);
    	for ( i = 0; i < n; i++)
    	{
    		scanf("%d", &a[i]);
    	}
    	max = a[0], min = a[0];
    	for ( j = 0; j < n; j++)
    	{
    		if (a[j] > max)
    		{
    			max = a[j];
    			maxp = j + 1;
    		}
    		if (min > a[j])
    		{
    			min = a[j];
    			minp = j + 1;
    		}
    	}
    	printf("%d %d\n", max, maxp);
    	printf("%d %d\n", min, minp);
    	return 0;
    }
    

    Pascal :

    var
    a:array[1..10000000]of integer;
    n,max,les,i,k,j:integer;
    begin
     readln(n);  read(a[1]);max:=a[1];les:=a[1];
     for i:=2 to n do
     begin
      read(a[i]);
      if max<a[i] then begin max:=a[i];k:=i;end;
      if les>a[i] then begin les:=a[i];j:=i;end;
     end;
     if max=a[1] then k:=1;
     if les=a[1] then j:=1;
     writeln(max,' ',k);
     writeln(les,' ',j);
    end.
    
    
    • 1

    信息

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