fork download
  1. #include <iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. #include<cmath>
  5. #define RPT 1000*1000*10
  6. #define RPT_J 1
  7. int main(){
  8. int number[1000]={0};
  9. for(auto nmbr = 0; nmbr<1000; nmbr++)
  10. number[nmbr]=0;
  11. long long i=0;
  12. long long j=0;
  13. long long digit_1 = 0;
  14. long long digit_2 = 0;
  15. long long digit_3 = 0;
  16. int z=0;
  17. double digit_prob[3];
  18.  
  19. for(j=0; j < RPT_J; j ++)
  20. {
  21. for(i=0; i < RPT; i ++)
  22. {
  23. z=pow(1000, (rand()%(RAND_MAX))/static_cast<double>(RAND_MAX));
  24. if(z>99 && z<1000)
  25. {
  26. digit_3++;
  27. }
  28. else if (z>9 && z<100)
  29. {
  30. digit_2++;
  31. }
  32. else
  33. {
  34. digit_1++;
  35. }
  36. number[z%1000]++;
  37. }
  38. digit_prob[1 -1] = (100.d*digit_1/static_cast<double>(i*(j+1)));
  39. digit_prob[2 -1] = (100.d*digit_2/static_cast<double>(i*(j+1)));
  40. digit_prob[3 -1] = (100.d*digit_3/static_cast<double>(i*(j+1)));
  41. std::cout<<"J: "<<j+1<<std::endl;
  42. std::cout<<"1 digit : "<<digit_prob[1 -1]<<" %"<<std::endl;
  43. std::cout<<"2 digit : "<<digit_prob[2 -1]<<" %"<<std::endl;
  44. std::cout<<"3 digit: "<<digit_prob[3 -1]<<" %"<<std::endl;
  45. }
  46. for(auto nmbr = 1; nmbr<10; nmbr++)
  47. std::cout<<nmbr<<": "<<100.d*static_cast<double>(number[nmbr])/(i*j)<<" %"<<std::endl;
  48. return 0;
  49. }
  50.  
  51.  
Success #stdin #stdout 1.98s 3412KB
stdin
Standard input is empty
stdout
J: 1
1 digit : 33.3214 %
2 digit : 33.3466 %
3 digit: 33.332 %
1: 10.0455 %
2: 5.84863 %
3: 4.16293 %
4: 3.22959 %
5: 2.63758 %
6: 2.23286 %
7: 1.93102 %
8: 1.70311 %
9: 1.53023 %