Advertisement
n_o_m_a_d

predict.c

Jun 20th, 2013
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int main(){
  4.     FILE *fin = fopen("testing/test_cases.txt","r");
  5.     FILE *fout = fopen("testing/Coutput.txt","w");
  6.     int test_cases;
  7.     fscanf (fin, "%d\n", &test_cases );
  8.     float p,gain;
  9.     while(test_cases-- > 0){
  10.         fscanf (fin, "%f\n", &p );
  11.         if(p >= .5){
  12.             gain = 10000 * (1-p) * (2*p-1);
  13.         }
  14.         else{
  15.             gain = p*(1-2*p)*10000;
  16.         }
  17.         float val = 10000+gain;
  18.         fprintf(fout, "%.6f\n",val);
  19.     }
  20.     fclose(fin);
  21.     fclose(fout);
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement