找距离最近油价最低的加油站(一)

2013-07-22 17:54:18 · 作者: · 浏览: 331

  C语言源码:

  [cpp]

  #include

  #include

  #include

  #define maxsize 600

  double lengthcmax,pricemin,falg;

  double cmax,length,davg;

  int n;

  typedef struct station

  {

  double price;

  double length;

  }station;

  station sta[maxsize];

  int cmp(const void *a,const void *b)

  {

  station *aa=(station *)a;

  station *bb=(station *)b;

  return aa->length>bb->length 1:-1;

  }

  int find(int i)

  {

  int j,fprice=INT_MAX;

  double price=INT_MAX;

  for(j=i+1;j=sta[j].length;j++)

  {

  if(sta[j].price

  {

  price=sta[j].price;

  fprice=j;

  }

  }

  if(fprice

  return fprice;

  else

  return -1;

  }

  int findmin(int i)

  {

  int j,fprice=INT_MAX;

  double price=INT_MAX;

  for(j=i+1;j=sta[j].length;j++)

  {

  if(sta[j].price

  {

  price=sta[j].price;

  fprice=j;

  }

  }

  if(fprice

  return fprice;

  else

  return -1;

  }

  void pri(int i,double oil)

  {//初始值0,0

  int j,k;

  j=find(i);//找离i站距离在一箱油之内的比i站油价低的站

  if(j!=-1)

  {//如果找到了

  k=i+1;

  while(k<=j)

  if(sta[k].price

  break;

  else