fork download
  1. #include <iostream>
  2. #include<cstdlib>
  3. #include<ctime>
  4. #define RPT 3*1000*1000*10
  5. #define RPT_J 2
  6. int main(){
  7. int number[1000]={0};
  8. for(auto nmbr = 0; nmbr<1000; nmbr++)
  9. number[nmbr]=0;
  10. long long i=0;
  11. long long j=0;
  12. long long digit_1 = 0;
  13. long long digit_2 = 0;
  14. long long digit_3 = 0;
  15. int z=0;
  16. double digit_prob[3];
  17.  
  18. for(j=0; j<RPT_J;j++)
  19. {
  20. for(i=0; i<RPT;i++)
  21. {
  22. int m=rand()%3+1;
  23. if(m==3)
  24. {
  25. z=(int)rand()%900+100;
  26. digit_3++;
  27. }
  28. else if(m==2)
  29. {
  30. z=(int)rand()%90+10;
  31. digit_2++;
  32. }
  33. else if(m==1)
  34. {
  35. z=(int)rand()%10;
  36. digit_1++;
  37. }
  38. number[z%1000]++;
  39. }
  40. digit_prob[1 -1] = (100.d*digit_1/static_cast<double>(i*(j+1)));
  41. digit_prob[2 -1] = (100.d*digit_2/static_cast<double>(i*(j+1)));
  42. digit_prob[3 -1] = (100.d*digit_3/static_cast<double>(i*(j+1)));
  43. std::cout<<"J: "<<j+1<<std::endl;
  44. std::cout<<"1 digit : "<<digit_prob[1 -1]<<" %"<<std::endl;
  45. std::cout<<"2 digit : "<<digit_prob[2 -1]<<" %"<<std::endl;
  46. std::cout<<"3 digit: "<<digit_prob[3 -1]<<" %"<<std::endl;
  47. }
  48. for(auto nmbr = 0; nmbr<10; nmbr++)
  49. std::cout<<nmbr<<": "<<100.d*static_cast<double>(number[nmbr])/(i*j)<<" %"<<std::endl;
  50. return 0;
  51. }
  52.  
Success #stdin #stdout 3.68s 3416KB
stdin
Standard input is empty
stdout
J: 1
1 digit : 33.3378 %
2 digit : 33.3216 %
3 digit: 33.3407 %
J: 2
1 digit : 33.3445 %
2 digit : 33.3177 %
3 digit: 33.3377 %
0: 3.33389 %
1: 3.33271 %
2: 3.33004 %
3: 3.33721 %
4: 3.33425 %
5: 3.33238 %
6: 3.33622 %
7: 3.33521 %
8: 3.33538 %
9: 3.33722 %