| ||||||||||
| 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???#include <stdio.h>
int mid(int a,int b,int c)
{
int e;
if(a>b)
{
e=a;
a=b;
b=e;
}
if(a>c)
{
e=a;
a=c;
c=e;
}
if(b>c)
{
e=b;
b=c;
c=e;
}
return(b);
}
int ab(int a,int b)
{
if(a>b) return(a-b);
else return(b-a);
}
main()
{
int a[102],b[102];
int sum,n,i;
scanf("%d",&n);
if(n==1) printf("0\n");
else
{
for(i=1;i<=n;i++) scanf("%d",&a[i]);
b[1]=a[1];
for(i=2;i<n;i++)
{
b[i]=mid(a[i],b[i-1],a[i+1]);
sum=sum+ab(a[i],b[i]);
sum=sum+ab(b[i],b[i-1]);
}
sum=sum+ab(a[n],b[n-1]);
printf("%d\n",sum);
}
return(0);
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator