2009-01-15 16:42:45來源不明

2008 NPSC C. 電費系統

/*************************************************************/

  1. #include<stdio.h>      
  2. #include<stdlib.h>   
  3. #include<string.h>   
  4. main()   
  5. {   
  6.  int a,b,n,N,temp=0;   
  7.  int x[51];   
  8.  while(scanf("%d",&n)==1&&n!=0)   
  9.   {        
  10.    temp=0;   
  11.    for(a=0;a<n;a++)   
  12.     {   
  13.     scanf("%d",&N);   
  14.     x[a]=N;      
  15.     }   
  16.    for(b=1;b<n;b++)   
  17.     {   
  18.      if(x[b-1]<x[b])   
  19.       temp=temp+(x[b]-x[b-1])*20;   
  20.      else if (x[b-1]>x[b])   
  21.       temp=temp+(x[b-1]-x[b])*10;   
  22.      else  
  23.       temp=temp;   
  24.     }    
  25.     printf("%d\n",temp);   
  26.   }      
  27.  return 0;        
  28. }