Advertisement
Guest User

Untitled

a guest
Jul 12th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. #include "guess_max_fn.c"
  4.  
  5. int main(int argc, char * argv[]) {
  6.     int N, count, real_idx;
  7.     double real_max = -1;
  8.     double your_max = -1;
  9.     int your_idx = -1;
  10.     int done = 0;
  11.  
  12. for (int plik=1; plik<=10000; plik++) {
  13.     char fn[1000];
  14.  
  15.     sprintf(fn, "/tmp/data/t%05d", plik);
  16.     FILE *f = fopen(fn, "r");
  17.  
  18.     reset(0.0);
  19.  
  20.     fscanf(f,"%d", &N);
  21.  
  22.     for(count=1; count<=N; count++) {
  23.         double x;
  24.         fscanf(f, "%lf", &x);
  25.         if (!done && (done=guess_max(x, N, count))) {
  26.             your_max = x;
  27.             your_idx = count;
  28.         }
  29.         if (real_max < x) {
  30.             real_max = x;
  31.             real_idx = count;
  32.         }
  33.     }
  34.  
  35.     if(your_max < real_max) {
  36.         printf("Pudło! (N=%d); Real max:%.15f (idx=%d); Your choice:%.15f (idx=%d)\n", N, real_max, real_idx, your_max, your_idx);
  37.     }else{
  38.         printf("Trafiony! (N=%d) idx=%d max=%.15f\n", N, real_idx, real_max );
  39.     }
  40.  
  41.     fclose(f);
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement