Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- int main()
- {
- FILE *fin, *fout;
- long int N, i, current;
- long int min = 1000;
- float max_profit = 1; //1 is the worst profit ratio we can have, by buying/selling on the same day
- fin = fopen("profit.in", "r");
- fout = fopen("profit.out", "w");
- fscanf(fin,"%ld", &N);
- for(i = 0; i < N ; i++)
- {
- fscanf(fin,"%ld", ¤t);
- if(current < min)
- {
- min = current;
- }
- else if( ((float)current/(float)min) > max_profit)
- {
- max_profit = (float)current/(float)min;
- }
- }
- fprintf(fout, "%0.3f\n", max_profit);
- fclose(fin);
- fclose(fout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement