| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我写成这样,怎么还是WA?请你们帮我看看#define M 50001
#include"stdio.h"
#include"math.h"
long com(long a[],long n)
{ int i, temp_max, temp_min, max, min;
temp_max = temp_min = a[0];
max = min = 0;
for(i=1;i<n;i++) {
if(a[i] > temp_max){
temp_max = a[i];
max = i;
}
if(a[i] < temp_min){
temp_min = a[i];
min = i;
}
}
if(max>min) return(max-min);
else return(-1);
}
int main()
{
long n,max;
long i,j;
long a[M];
while (scanf("%ld",&n)==1)
{
j=0;
max=0;
for (i=0;i<n;i++)
{
scanf("%ld",&a[i]);
}
max=com(a,n);
printf("%ld\n",max);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator