Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

想不通为什么我的会WA???

Posted by jackie_wyx at 2006-08-25 14:16:54 on Problem 2313
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator