Advertisement
Guest User

Untitled

a guest
Jan 24th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. int main()
  4. {
  5.   FILE *fin, *fout;
  6.   long int N, i, current;
  7.   long int min = 1000;
  8.   float max_profit = 1; //1 is the worst profit ratio we can have, by buying/selling on the same day
  9.  
  10.   fin = fopen("profit.in", "r");
  11.   fout = fopen("profit.out", "w");
  12.  
  13.   fscanf(fin,"%ld", &N);
  14.  
  15.   for(i = 0; i < N ; i++)
  16.   {
  17.     fscanf(fin,"%ld", &current);
  18.     if(current < min)
  19.     {
  20.       min = current;
  21.     }
  22.     else if( ((float)current/(float)min) > max_profit)
  23.     {
  24.       max_profit = (float)current/(float)min;
  25.     }
  26.   }
  27.  
  28.   fprintf(fout, "%0.3f\n", max_profit);
  29.  
  30.   fclose(fin);
  31.   fclose(fout);
  32.  
  33.   return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement