Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. #include "bits\stdc++.h"
  2. using namespace std;
  3. int main()
  4. {
  5. vector<float> vec;
  6. FILE *fp;
  7. int i;
  8. float x,y;
  9. if ((fp=fopen("D:\\Games\\1.txt","w"))==NULL)
  10. {
  11. printf("error");
  12. }
  13. else
  14. {
  15. for (int i = 0; i < 100; i++)
  16. {
  17. x=rand()/32767.0;
  18. y=(-0.5f)*log(x);
  19. vec.push_back(y);
  20. }
  21. sort(vec.begin(),vec.end());
  22. double sekay = 0.5;
  23. int ind = 0;
  24. while(sekay < 4)
  25. {
  26. int am = 0;
  27. while(ind < vec.size() && vec[ind] < sekay)
  28. {
  29. am++;
  30. ind++;
  31. }
  32. fprintf(fp, "From %f to %f - %d \n",sekay-0.5,sekay,am);
  33. sekay+=0.5;
  34. }
  35. fclose(fp);
  36. }
  37. return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement